diff --git a/kjb-docs/Property 설정.md b/kjb-docs/Property 설정.md new file mode 100644 index 0000000..e6c9739 --- /dev/null +++ b/kjb-docs/Property 설정.md @@ -0,0 +1,39 @@ +# 광주은행용 Property 설정 +## 참고 Class +- com.eactive.ext.kjb.common.KjbProperty + +## Monitoring +### UMS 관련 (kjb.ums) +- 실제 광주은행 내에서는 UMS 는 SMS/LMS/알림톡 등 만 담당. +- 이메일 발송은 별도 시스템이 있음 (JSON 형식의 파일로 EAI 배치 이용 연계) + +- kjb.eai_batch.url + - 개발 : http://172.31.32.111:10230/BATAppWeb/EaiBatCall + - 검증 : http://172.31.33.111:10430/BATAppWeb/EaiBatCall + - 운영 : http://172.21.1.40:10860/BATAppWeb/EaiBatCall +- kjb.ums.host_url + - 개발 : http://172.31.35.144:9021 + - 운영 : +- kjb.ums.api_key + - 개발 API KEY(192.168.240.176) : `7cca6d58-e4f7-474d-9edd-525806bc99ff` + - 운영 API KEY(192.168.132.77 / 192.168.132.78 / 192.168.157.77 ) : `6a40a69f-5614-485b-8d0f-6fb2e2e51bfe` +- kjb.ums.eai_batch.send_dir : /Data/eapim/portal/sendmail/snd +- kjb.ums.eai_batch.backup_dir : /Data/eapim/portal/sendmail/bak + + +## 개발 Property + +| Key | 이름 | Value | 분류 | | +| ------------------------------------ | ------------------------ | ----------------------------------------------- | --- | --- | +| kjb.eai_batch.url | EAI 배치 호출 주소 | http://172.31.32.111:10230/BATAppWeb/EaiBatCall | 이메일 | | +| kjb.ums.eai_batch.connection_timeout | EAI 배치 커넥션 타임아웃(seconds) | 5 | 이메일 | | +| kjb.ums.eai_batch.response_timeout | EAI 배치 응답 타임아웃(seconds) | 10 | 이메일 | | +| kjb.ums.eai_batch.send_dir | EAI 배치 발송용 디렉토리 | /Data/eapim/portal/sendmail/snd | 이메일 | | +| kjb.ums.eai_batch.backup_dir | EAI 배치 발송 이후 백업 디렉토리 | /Data/eapim/portal/sendmail/bak | 이메일 | | +| kjb.ums.eai_batch.interface_id | 고객이메일발송용 EAI 배치 인터페이스 | UAGFF00001UIE | 알림톡 | | +| kjb.ums.host_url | UMS 호출 주소 | http://172.31.35.144:9021 | 알림톡 | | +| kjb.ums.api_key | UMS API Key | 7cca6d58-e4f7-474d-9edd-525806bc99ff | 알림톡 | | +| kjb.ums.connection_timeout | UMS 커넥션 타임아웃(seconds) | 5 | 알림톡 | | +| kjb.ums.response_timeout | UMS 응답 타임아웃(seconds) | 10 | 알림톡 | | + +- \ No newline at end of file diff --git a/src/main/java/com/eactive/eai/rms/onl/common/service/UmsDispatchJob.java b/src/main/java/com/eactive/eai/rms/onl/common/service/UmsDispatchJob.java index 9b2c31c..1492d23 100644 --- a/src/main/java/com/eactive/eai/rms/onl/common/service/UmsDispatchJob.java +++ b/src/main/java/com/eactive/eai/rms/onl/common/service/UmsDispatchJob.java @@ -2,6 +2,7 @@ package com.eactive.eai.rms.onl.common.service; import com.eactive.eai.rms.onl.common.service.ums.UmsDispatchService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; @@ -28,6 +29,25 @@ public class UmsDispatchJob implements Job { @Override public void execute(JobExecutionContext context) throws JobExecutionException { log.info("Starting Message Dispatch Job..."); + + // inst.Name 이 지정된 경우 해당 인스턴스에서만 동작 + String jobInstName = context.getJobDetail().getJobDataMap().getString("inst.Name"); + if (StringUtils.isNotEmpty(jobInstName)) { + log.debug("Job 실행 인스턴스 명이 지정되어 있음 - {}", jobInstName); + + jobInstName = jobInstName.trim(); + String instanceName = System.getProperty("inst.Name"); + if (StringUtils.isNotEmpty(instanceName)) { + log.debug("현재 인스턴스 명 : {}", instanceName); + instanceName = instanceName.trim(); + + if (!jobInstName.equalsIgnoreCase(instanceName)) { + log.debug("Job 인스턴스명과 현재 인스턴스명이 다름. 종료 처리"); + return; + } + } + } + try { umsDispatchService.processMessages(); } catch (Exception e) { diff --git a/src/main/java/com/eactive/eai/rms/onl/common/service/ums/UmsDispatchService.java b/src/main/java/com/eactive/eai/rms/onl/common/service/ums/UmsDispatchService.java index ad361f8..30951e5 100644 --- a/src/main/java/com/eactive/eai/rms/onl/common/service/ums/UmsDispatchService.java +++ b/src/main/java/com/eactive/eai/rms/onl/common/service/ums/UmsDispatchService.java @@ -1,9 +1,13 @@ package com.eactive.eai.rms.onl.common.service.ums; import com.eactive.apim.portal.template.entity.MessageRequest; - -import edu.emory.mathcs.backport.java.util.Collections; +import com.eactive.eai.rms.data.entity.man.monitoringProperty.service.MonitoringPropertyService; +import com.eactive.ext.kjb.common.KjbProperty; +import com.eactive.ext.kjb.safedb.KjbSafedbWrapper; +import com.eactive.ext.kjb.ums.KjbEmailService; +import com.eactive.ext.kjb.ums.KjbUmsService; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.NotImplementedException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Service; @@ -15,15 +19,17 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import java.io.IOException; import java.time.LocalDateTime; -import java.util.ArrayList; import java.util.List; -import java.util.concurrent.*; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; @Slf4j @Service @Transactional(transactionManager = "transactionManagerForEMS") public class UmsDispatchService { + public static final String PROP_GORUP_ID = "Monitoring"; private final ThreadPoolExecutor executorService; private final TransactionTemplate transactionTemplate; @@ -36,15 +42,23 @@ public class UmsDispatchService { @PersistenceContext(unitName = "entityManagerFactoryForEMS") private EntityManager entityManager; - @Autowired - private UmsSender umsSender; +// private final KjbEmailService kjbEmailService; +// private final KjbSafedbWrapper kjbSafedbWrapper; +// private final MonitoringPropertyService monitoringPropertyService; + + private final KjbUmsService kjbUmsService; - @Autowired - private StandardMessageFactory messageFactory; @Autowired public UmsDispatchService( - @Qualifier("transactionManagerForEMS") PlatformTransactionManager transactionManager) { + @Qualifier("transactionManagerForEMS") PlatformTransactionManager transactionManager, +// KjbSafedbWrapper kjbSafedbWrapper, + MonitoringPropertyService monitoringPropertyService + ) { +// this.kjbEmailService = kjbEmailService; +// this.kjbSafedbWrapper = kjbSafedbWrapper; +// this.monitoringPropertyService = monitoringPropertyService; + this.executorService = new ThreadPoolExecutor( CORE_POOL_SIZE, MAX_POOL_SIZE, @@ -56,6 +70,17 @@ public class UmsDispatchService { this.transactionTemplate = new TransactionTemplate(transactionManager); log.debug("UmsDispatchService initialized with thread pool - core: {}, max: {}, queue: {}", CORE_POOL_SIZE, MAX_POOL_SIZE, QUEUE_CAPACITY); + + + KjbProperty prop = new KjbProperty(); + prop.setEaiBatchUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.url")); + prop.setUmsEaiBatchSendDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.send_dir")); + prop.setUmsEaiBatchBackupDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.backup_dir")); + prop.setUmsEaiBatchInterfaceId(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.interface_id")); + prop.setUmsHostUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.host_url")); + prop.setUmsApiKey(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.api_key")); + + this.kjbUmsService = new KjbUmsService(prop); } @SuppressWarnings("unchecked") @@ -110,7 +135,18 @@ public class UmsDispatchService { try { transactionTemplate.execute(status -> { try { - processMessage(message); + // 광주은행에서는 사용하지 않는 메소드 +// processMessage(message); + + if (KjbUmsService.isAllowChannel(message)) { + kjbUmsService.send(message); + } + + if (KjbEmailService.isAllowChannel(message)) { + throw new NotImplementedException(); +// kjbEmailService.sendEmail(message); + } + return null; } catch (Exception e) { log.error("Failed to process message: {} - Error: {}", @@ -127,21 +163,27 @@ public class UmsDispatchService { }); } - public void processMessage(MessageRequest message) throws IOException { - try { - String standardMessage = messageFactory.createMessage(message); - log.debug("Processing message ID: {} - Type: {}", message.getId(), message.getMessageType()); - - umsSender.sendMessage(standardMessage); - updateMessageStatus(message, "SENT"); - log.debug("Successfully processed and sent message ID: {}", message.getId()); - } catch (Exception e) { - log.error("Message processing failed for ID: {} - Error: {}", - message.getId(), e.getMessage(), e); - updateMessageStatus(message, "FAILED"); - throw e; - } - } + /** + * kbank 방식으로 광주은행에서는 사용하지 않음 + * @param message + * @throws IOException + */ +// @Deprecated +// public void processMessage(MessageRequest message) throws IOException { +// try { +// String standardMessage = messageFactory.createMessage(message); +// log.debug("Processing message ID: {} - Type: {}", message.getId(), message.getMessageType()); +// +// umsSender.sendMessage(standardMessage); +// updateMessageStatus(message, "SENT"); +// log.debug("Successfully processed and sent message ID: {}", message.getId()); +// } catch (Exception e) { +// log.error("Message processing failed for ID: {} - Error: {}", +// message.getId(), e.getMessage(), e); +// updateMessageStatus(message, "FAILED"); +// throw e; +// } +// } public void updateMessageStatus(MessageRequest message, String status) { message.setRequestStatus(status); diff --git a/src/main/java/com/eactive/eai/rms/onl/common/service/ums/UmsSender.java b/src/main/java/com/eactive/eai/rms/onl/common/service/ums/UmsSender.java index cd2ff04..4a95ca1 100644 --- a/src/main/java/com/eactive/eai/rms/onl/common/service/ums/UmsSender.java +++ b/src/main/java/com/eactive/eai/rms/onl/common/service/ums/UmsSender.java @@ -16,8 +16,12 @@ import org.springframework.stereotype.Component; import java.io.IOException; import java.nio.charset.StandardCharsets; +/** + * 25.11.05 - 광주은행 미사용 클래스 + */ @Slf4j @Component +@Deprecated public class UmsSender { private final MonitoringPropertyService monitoringPropertyService; diff --git a/src/main/java/com/eactive/ext/kjb/ums/KjbUmsService.java b/src/main/java/com/eactive/ext/kjb/ums/KjbEmailService.java similarity index 66% rename from src/main/java/com/eactive/ext/kjb/ums/KjbUmsService.java rename to src/main/java/com/eactive/ext/kjb/ums/KjbEmailService.java index 08c3ccd..334a336 100644 --- a/src/main/java/com/eactive/ext/kjb/ums/KjbUmsService.java +++ b/src/main/java/com/eactive/ext/kjb/ums/KjbEmailService.java @@ -1,5 +1,6 @@ package com.eactive.ext.kjb.ums; +import com.eactive.apim.portal.template.entity.MessageCode; import com.eactive.apim.portal.template.entity.MessageRequest; import com.eactive.eai.rms.common.base.BaseService; import com.eactive.eai.rms.data.entity.man.monitoringProperty.service.MonitoringPropertyService; @@ -22,7 +23,9 @@ import java.util.Arrays; @Service @Transactional(transactionManager = "transactionManagerForEMS") @Slf4j -public class KjbUmsService extends BaseService { +public class KjbEmailService extends BaseService { + public final static int[] ALLOW_CHANNELS = { MessageCode.Channels.EMAIL.getValue() }; + public static final String PROP_GORUP_ID = "Monitoring"; public static final String PROP_EAI_BATCH_URL = "kjb.ums.eai_batch.url"; public static final String PROP_EAI_BATCH_SEND_DIR = "kjb.ums.eai_batch.send_dir"; @@ -34,19 +37,33 @@ public class KjbUmsService extends BaseService { @Autowired - public KjbUmsService(KjbSafedbWrapper kjbSafedbWrapper, - MonitoringPropertyService monitoringPropertyService) { - this.kjbSafedbWrapper = kjbSafedbWrapper; + public KjbEmailService(MonitoringPropertyService monitoringPropertyService) { + this.kjbSafedbWrapper = KjbSafedbWrapper.getInstance(); KjbProperty prop = new KjbProperty(); - prop.setEaiBatchUrl(monitoringPropertyService.getPropertyValue(PROP_GORUP_ID, PROP_EAI_BATCH_URL, "")); - prop.setEaiBatchSendDir(monitoringPropertyService.getPropertyValue(PROP_GORUP_ID, PROP_EAI_BATCH_SEND_DIR, "/Data/files/send")); + prop.setEaiBatchUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, PROP_EAI_BATCH_URL)); + prop.setUmsEaiBatchSendDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, PROP_EAI_BATCH_SEND_DIR)); + prop.setUmsEaiBatchBackupDir(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.backup_dir")); + prop.setUmsEaiBatchInterfaceId(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.eai_batch.interface_id")); + prop.setUmsHostUrl(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.host_url")); + prop.setUmsApiKey(monitoringPropertyService.getPrpty2ValById(PROP_GORUP_ID, "kjb.ums.api_key")); this.prop = prop; } - public KjbUmsService(KjbSafedbWrapper kjbSafedbWrapper, - KjbProperty property) { + + public static boolean isAllowChannel(MessageRequest message) { + for (int channel : ALLOW_CHANNELS) { + if ((message.getMessageCode().getChannels() & channel) == channel) { + return true; + } + } + return false; + } + + + public KjbEmailService(KjbSafedbWrapper kjbSafedbWrapper, + KjbProperty property) { this.kjbSafedbWrapper = kjbSafedbWrapper; this.prop = property; @@ -60,34 +77,34 @@ public class KjbUmsService extends BaseService { } log.info("EAI Batch URL: {}", prop.getEaiBatchUrl()); - log.info("EAI Batch Send Dir: {}", prop.getEaiBatchSendDir()); + log.info("EAI Batch Send Dir: {}", prop.getUmsEaiBatchSendDir()); // 디렉토리 검사(쓰기 권한 포함) - Path sendDirPath = Paths.get(prop.getEaiBatchSendDir()); + Path sendDirPath = Paths.get(prop.getUmsEaiBatchSendDir()); if (!sendDirPath.toFile().exists()) { // 생성 시도 boolean created = sendDirPath.toFile().mkdirs(); if (!created) { - log.error("EAI_BATCH_SEND_DIR 디렉토리를 생성할 수 없음: {}", prop.getEaiBatchSendDir()); - throw new IllegalStateException("EAI_BATCH_SEND_DIR 디렉토리를 생성할 수 없음: " + prop.getEaiBatchSendDir()); + log.error("EAI_BATCH_SEND_DIR 디렉토리를 생성할 수 없음: {}", prop.getUmsEaiBatchSendDir()); + throw new IllegalStateException("EAI_BATCH_SEND_DIR 디렉토리를 생성할 수 없음: " + prop.getUmsEaiBatchSendDir()); } } if (!sendDirPath.toFile().isDirectory()) { - log.error("EAI_BATCH_SEND_DIR 가 디렉토리가 아님: {}", prop.getEaiBatchSendDir()); - throw new IllegalStateException("EAI_BATCH_SEND_DIR 가 디렉토리가 아님: " + prop.getEaiBatchSendDir()); + log.error("EAI_BATCH_SEND_DIR 가 디렉토리가 아님: {}", prop.getUmsEaiBatchSendDir()); + throw new IllegalStateException("EAI_BATCH_SEND_DIR 가 디렉토리가 아님: " + prop.getUmsEaiBatchSendDir()); } if (!sendDirPath.toFile().canWrite()) { - log.error("EAI_BATCH_SEND_DIR 에 쓰기 권한이 없음: {}", prop.getEaiBatchSendDir()); - throw new IllegalStateException("EAI_BATCH_SEND_DIR 에 쓰기 권한이 없음: " + prop.getEaiBatchSendDir()); + log.error("EAI_BATCH_SEND_DIR 에 쓰기 권한이 없음: {}", prop.getUmsEaiBatchSendDir()); + throw new IllegalStateException("EAI_BATCH_SEND_DIR 에 쓰기 권한이 없음: " + prop.getUmsEaiBatchSendDir()); } } public void sendEmail(MessageRequest messageRequest) { - log.debug("sendEmail() called - EAI_BATCH_URL: {}, EAI_BATCH_SEND_DIR: {}", prop.getEaiBatchUrl(), prop.getEaiBatchSendDir()); + log.debug("sendEmail() called - EAI_BATCH_URL: {}, EAI_BATCH_SEND_DIR: {}", prop.getEaiBatchUrl(), prop.getUmsEaiBatchSendDir()); log.debug("MessageRequest ID: {}, Email: {}", messageRequest.getId(), messageRequest.getEmail());