제주은행 메신저 발송

This commit is contained in:
eastargh
2026-06-02 13:30:59 +09:00
parent d32005450f
commit 777ca3a6a6
4 changed files with 212 additions and 0 deletions
@@ -0,0 +1,41 @@
package com.eactive.ext.djb.apistatus;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class DjbIncidentDetectionService {
private static final Logger log = LoggerFactory.getLogger(DjbIncidentDetectionService.class);
/**
* 이벤트 감지
* @param event "CONTROL_START" : 점검시작
"CONTROL_END" : 점검종료
"ERROR_START" : 장애시작
"ERROR_END" : 장애종료
"DELAY_START" : 지연시작
"DELAY_END" : 지연종료
* @param apiIds API IDs
*/
public void detect(String event, List<String> apiIds) {
log.debug("이벤트 감지: {} {}", event, apiIds);
}
// API FSM 내 아직 장애로 남아있는 API 목록
public void remainDownApiIds() {
}
// 정상 동작 - detect()에서 일괄 처리 (복구 = 점검종료, 장애종료, 지연종료)
// public void recovered(String event, String[] apiIds) {
//
// }
}
@@ -0,0 +1,29 @@
package com.eactive.ext.djb.apistatus.event;
import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Component;
import com.eactive.apim.portal.template.entity.MessageCode;
import com.eactive.apim.portal.template.service.MessageEventHandler;
import com.eactive.apim.portal.template.service.MessageRecipient;
import com.eactive.apim.portal.template.service.MessageSendEvent;
@Component
public class ApiStatusChangedEventHandler implements MessageEventHandler {
@Override
public MessageCode getKey() { return MessageCode.API_STATUS_CHANGED; }
@Override
public MessageSendEvent createEvent(Object source, MessageRecipient recipient, Map<String, Object> params) {
Map<String, String> p = new HashMap<>();
params.forEach((k, v) -> p.put(k, v != null ? v.toString() : null));
return new MessageSendEvent(source, getKey(), recipient, p);
}
@Override public boolean allowAdditionalRecipients() { return true; }
@Override public String getDisplayName() { return "API 상태 변경"; }
@Override public String getDescription() { return "API 상태가 변경되었습니다"; }
}
@@ -0,0 +1,131 @@
package com.eactive.ext.djb.ums;
import java.io.BufferedReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import org.apache.commons.lang3.StringUtils;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.util.Timeout;
import com.eactive.apim.portal.template.entity.MessageCode;
import com.eactive.apim.portal.template.entity.MessageRequest;
import com.eactive.ext.kjb.common.KjbProperty;
import com.eactive.ext.kjb.common.KjbPropertyHolder;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class DjbMessengerService {
public final static int[] ALLOW_CHANNELS = { MessageCode.Channels.MESSENGER.getValue() };
private static volatile DjbMessengerService instance;
private DjbMessengerService() {
// 싱글톤
}
public static DjbMessengerService getInstance() {
if (instance == null) {
synchronized (DjbMessengerService.class) {
if (instance == null) {
instance = new DjbMessengerService();
}
}
}
return instance;
}
private KjbProperty getProperty() {
return KjbPropertyHolder.get();
}
private boolean isRealMode() {
String url = getProperty().getUmsHostUrl();
return url != null && StringUtils.isNotEmpty(url.trim());
}
private CloseableHttpClient createHttpClient() {
return HttpClients.createDefault();
}
private RequestConfig createRequestConfig() {
KjbProperty prop = getProperty();
return RequestConfig.custom()
.setConnectTimeout(Timeout.ofSeconds(prop.getUmsConnectionTimeout()))
.setResponseTimeout(Timeout.ofSeconds(prop.getUmsResponseTimeout()))
.build();
}
public static boolean isAllowChannel(MessageRequest message) {
for (int channel : ALLOW_CHANNELS) {
if ((message.getMessageCode().getChannels() & channel) == channel) {
return true;
}
}
return false;
}
public boolean send(MessageRequest messageRequest) throws Exception {
if (messageRequest == null) {
throw new IllegalArgumentException("messageRequest is null");
}
if (MessageCode.Channels.MESSENGER.getValue() != (messageRequest.getMessageCode().getChannels() & MessageCode.Channels.MESSENGER.getValue())) {
log.error("지원하지 않는 발송 채널 - {}", messageRequest.getMessageCode().toString());
throw new IllegalArgumentException("지원하지 않는 발송 채널 - " + messageRequest.getMessageCode().toString());
}
this.httpConnection(messageRequest);
return true;
}
private void httpConnection(MessageRequest messageRequest) throws Exception {
URL url = new URL(getProperty().getSwingUrl());
int timeoutvalue = 5 * 1000; // 타임아웃 설정을 위한 값 (단위: ms)
// Charset charset = Charset.forName("UTF-8");
Charset charset = Charset.forName("MS949");
HttpURLConnection conn = null;
BufferedReader br = null;
StringBuffer sb = null;
// String bodyData = this.makeBodyData(cnslDivCdval);
// String responseData = "";
// String method = bodyData != "" ? "POST" : "GET";
// conn " (HttpURL Connection) url.openConnection();
// conn.setRequestMethod(method); // w #4
// // conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
// conn.setRequestProperty("Content-Type", "application/json; charset=MS949");
// conn.setConnectTimeout(timeoutValue); // Cz EGoR 48(5=)
// conn.setReadTimeout(timeoutValue); // 8 #gOR N8(5s)
// conn.setDoOutput(true);
// // POst 40
// if (method.equals("POST")) (
// Outputstream os = conn.getOutputStream();
// byte requestData[] - bodyData.getBytes(charset);
// os.write(requestData);
// os.close();
// ph
// System.out.println("getContentType():"t conn.getContentType());
// System,out.println("getResponseCode();" t conn.getResponseCode());
// System.out.println("getResponseMessage();" + conn.getResponseMessage());
// if (LOG_DEBUG, isDebugEnabled()) (
// LOG_DEBUG. debug("getContentType();" + conn.getContentType()); // 5 0= 5 #7
// LOG_DEBUG. debug("getResponsecode();" + conn.getResponseCode()); // ## #5 7#7|
// LOG_DEBUG. debug("getResponseMessage():" + conn.getResponseMessage()); //
}
private String makeBodyData() {
return "";
}
}
@@ -191,6 +191,17 @@ public class KjbProperty {
private Integer apiGwMetricPageSize = 10000;
// 제주은행 swing chat (messenger)
@KjbPropertyValue(key = "djb.swing.url", defaultValue = "http://172.31.35.144:9021")
@NotEmpty
private String swingUrl = "";
public String toJsonString(boolean isPretty) {
return isPretty
? new GsonBuilder().setPrettyPrinting().create().toJson(this)