비동기 로그 배치 커밋 적용
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.eactive.eai.common.logger;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.eactive.eai.adapter.ElinkAdapter;
|
||||
@@ -176,6 +177,83 @@ public class DBLogTransactionLogger implements TransactionLogger {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 1. 기능 : 여러 건의 로깅 정보를 한 트랜잭션으로 적재 (COMMIT 1회)
|
||||
* 2. 처리 개요 :
|
||||
* - log()의 건별 처리와 달리 COMMIT 횟수를 배치 크기만큼 줄인다.
|
||||
* - LOG_TYPE 판정 규칙은 log()과 동일하게 유지한다.
|
||||
* 3. 주의사항
|
||||
* - 실시간 모니터링(EAIServiceMonitor) 전달은 발행측 EAILogSender.send()에서
|
||||
* 이미 처리하므로 여기서는 다루지 않는다.
|
||||
*
|
||||
* @param items {EAIMessage, Properties} 쌍의 목록
|
||||
**/
|
||||
public void logBatch(List<Object[]> items) {
|
||||
if (items == null || items.isEmpty()) return;
|
||||
logCount += items.size();
|
||||
try {
|
||||
insertLogBatch(items);
|
||||
} catch (Exception e) {
|
||||
errCount++;
|
||||
if (logger.isError()) logger.error("DBLogTransactionLogger] logBatch ERROR. - " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void insertLogBatch(List<Object[]> items) {
|
||||
if (items == null || items.isEmpty()) return;
|
||||
|
||||
// Direct DB Logging - 판정 규칙은 log()과 동일
|
||||
String logType = "DB";
|
||||
String setLogType = PropManager.getInstance().getProperty("LOG_TYPE");
|
||||
if (setLogType != null) {
|
||||
logType = setLogType;
|
||||
}
|
||||
|
||||
if (!"DB".equals(logType) || !EAIDBLogControl.isEnable()) {
|
||||
for (Object[] item : items) {
|
||||
writeFileLog((EAIMessage) item[0], (Properties) item[1]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
EAILogBatchWriter writer = ApplicationContextProvider.getContext().getBean(EAILogBatchWriter.class);
|
||||
try {
|
||||
writer.writeBatch(items);
|
||||
} catch (Exception be) {
|
||||
// 배치는 한 건만 실패해도 트랜잭션 전체가 롤백된다.
|
||||
// 정상 건까지 유실되지 않도록 건별 독립 트랜잭션으로 재시도한다.
|
||||
if (logger.isError()) {
|
||||
logger.error("DBLogTransactionLogger] insertLogBatch failed, retry one by one. size=" + items.size(), be);
|
||||
}
|
||||
for (Object[] item : items) {
|
||||
EAIMessage eaiMessage = (EAIMessage) item[0];
|
||||
Properties prop = (Properties) item[1];
|
||||
try {
|
||||
writer.writeOne(eaiMessage, prop);
|
||||
} catch (Exception e) {
|
||||
String message = e.getMessage();
|
||||
// DB Connection Error일 경우에만 DB 로깅을 중단한다.
|
||||
if ("ConnectionError".equals(message) || StringUtils.contains(message, "JDBCConnectionException")
|
||||
|| StringUtils.contains(message, "Unable to acquire JDBC Connection")) {
|
||||
EAIDBLogControl.setEnable(false);
|
||||
}
|
||||
if (logger.isError()) {
|
||||
logger.error("DBLogTransactionLogger] insertLogBatch single retry failed. - " + message, e);
|
||||
}
|
||||
writeFileLog(eaiMessage, prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeFileLog(EAIMessage eaiMessage, Properties prop) {
|
||||
try {
|
||||
EAIFileLogger.getInstance().setLog(eaiMessage, prop);
|
||||
} catch (Exception fe) {
|
||||
if (logger.isError()) logger.error("DBLogTransactionLogger] file log failed. - " + fe.getMessage(), fe);
|
||||
}
|
||||
}
|
||||
|
||||
public static void insertLog(EAIMessage eaiMessage, Properties prop) throws EAILogException {
|
||||
String guidLogPrefix = "DBLogTransactionLogger] GUID["+ eaiMessage.getMapper().getGuid(eaiMessage.getStandardMessage())
|
||||
+"] UUID["+eaiMessage.getSvcOgNo()+"] ";
|
||||
|
||||
Reference in New Issue
Block a user