feat: TxSiftContext 추가 및 HttpAdapterServiceSupport 적용
- TxSiftContext 클래스 추가: SIFT MDC 등록/해제 및 appender close 공통 처리
- begin(): isSiftEnabled() 확인 후 MDC 등록, 이미 설정된 경우 스킵
- end(): appender 즉시 close 후 MDC 제거 (UUID 등 1회성 key 용도)
- HttpAdapterServiceSupport: MDC 직접 제어 코드를 TxSiftContext.begin/end로
교체
This commit is contained in:
@@ -19,6 +19,7 @@ import com.eactive.eai.adapter.http.dynamic.filter.HttpAdapterFilterType;
|
|||||||
import com.eactive.eai.adapter.http.dynamic.filter.JwtAuthException;
|
import com.eactive.eai.adapter.http.dynamic.filter.JwtAuthException;
|
||||||
import com.eactive.eai.common.TransactionContextKeys;
|
import com.eactive.eai.common.TransactionContextKeys;
|
||||||
import com.eactive.eai.common.util.Logger;
|
import com.eactive.eai.common.util.Logger;
|
||||||
|
import com.eactive.eai.common.util.TxSiftContext;
|
||||||
import com.eactive.eai.common.util.UUIDGenerator;
|
import com.eactive.eai.common.util.UUIDGenerator;
|
||||||
|
|
||||||
public abstract class HttpAdapterServiceSupport implements HttpAdapterService, HttpAdapterServiceKey {
|
public abstract class HttpAdapterServiceSupport implements HttpAdapterService, HttpAdapterServiceKey {
|
||||||
@@ -37,10 +38,7 @@ public abstract class HttpAdapterServiceSupport implements HttpAdapterService, H
|
|||||||
prop.setProperty(TransactionContextKeys.TRANSACTION_UUID, uuid);
|
prop.setProperty(TransactionContextKeys.TRANSACTION_UUID, uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(MDC.get(Logger.DISCRIMINATOR) == null) {
|
bMDCput = TxSiftContext.begin(uuid);
|
||||||
MDC.put(Logger.DISCRIMINATOR, uuid);
|
|
||||||
bMDCput = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String transactionId = request.getHeader(HttpClientAdapterServiceKey.TRANSACTION_ID);
|
String transactionId = request.getHeader(HttpClientAdapterServiceKey.TRANSACTION_ID);
|
||||||
@@ -93,7 +91,7 @@ public abstract class HttpAdapterServiceSupport implements HttpAdapterService, H
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if(bMDCput)
|
if(bMDCput)
|
||||||
MDC.remove(Logger.DISCRIMINATOR);
|
TxSiftContext.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.eactive.eai.common.util;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.slf4j.MDC;
|
||||||
|
|
||||||
|
public class TxSiftContext {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 거래 시작 시 SIFT discriminator를 MDC에 등록한다.
|
||||||
|
* SIFT가 비활성화 상태이면 아무 작업도 하지 않는다.
|
||||||
|
*/
|
||||||
|
public static boolean begin(String discriminatingValue) {
|
||||||
|
if (!Logger.isSiftEnabled()) return false;
|
||||||
|
if(MDC.get(Logger.DISCRIMINATOR) == null) {
|
||||||
|
MDC.put(Logger.DISCRIMINATOR, discriminatingValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 거래 종료 시 MDC에 등록된 SIFT appender를 닫고 MDC를 정리한다.
|
||||||
|
* begin() 에서 MDC가 설정되지 않았으면 아무 작업도 하지 않는다.
|
||||||
|
*/
|
||||||
|
public static void end() {
|
||||||
|
String discriminatingValue = MDC.get(Logger.DISCRIMINATOR);
|
||||||
|
if (StringUtils.isBlank(discriminatingValue)) return;
|
||||||
|
Logger.closeSiftAppender(discriminatingValue);
|
||||||
|
MDC.remove(Logger.DISCRIMINATOR);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user