feature: circuitBreaker 타입 처리 및 RESTProcess 개선
This commit is contained in:
+8
-12
@@ -18,7 +18,7 @@ import com.eactive.eai.data.entity.onl.circuitbreaker.CircuitBreakerConfig;
|
|||||||
@Service
|
@Service
|
||||||
@Transactional
|
@Transactional
|
||||||
public class TypedCircuitBreakerDAO extends BaseDAO {
|
public class TypedCircuitBreakerDAO extends BaseDAO {
|
||||||
private static Logger logger;
|
private static Logger logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
||||||
@Autowired
|
@Autowired
|
||||||
private CircuitBreakerConfigLoader loader;
|
private CircuitBreakerConfigLoader loader;
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -41,26 +41,22 @@ public class TypedCircuitBreakerDAO extends BaseDAO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TypedCircuitBreakerVO get(String key) throws DAOException {
|
public TypedCircuitBreakerVO get(String key) throws DAOException {
|
||||||
TypedCircuitBreakerVO var3;
|
TypedCircuitBreakerVO vo;
|
||||||
try {
|
try {
|
||||||
logger.info("[ @@ Load UrlCircuitBreaker Configuration - starting >>>>>>>>>>>>>>>>> " + key + "]");
|
logger.info("[ @@ Load UrlCircuitBreaker Configuration - starting >>>>>>>>>>>>>>>>> " + key + "]");
|
||||||
Optional<CircuitBreakerConfig> optionalRow = this.loader.findById(key);
|
Optional<CircuitBreakerConfig> optionalRow = this.loader.findById(key);
|
||||||
if (!optionalRow.isPresent()) {
|
if (!optionalRow.isPresent()) {
|
||||||
var3 = null;
|
vo = null;
|
||||||
return var3;
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
var3 = this.mapper.toVo((CircuitBreakerConfig) optionalRow.get());
|
vo = this.mapper.toVo((CircuitBreakerConfig) optionalRow.get());
|
||||||
} catch (Exception var7) {
|
} catch (Exception e) {
|
||||||
throw new DAOException(ExceptionUtil.getErrorCode(var7, "RECEAICMM101"));
|
throw new DAOException(ExceptionUtil.getErrorCode(e, "RECEAICMM101"));
|
||||||
} finally {
|
} finally {
|
||||||
logger.info("[>> Load UrlCircuitBreaker Configuration - ended " + key + "]");
|
logger.info("[>> Load UrlCircuitBreaker Configuration - ended " + key + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
return var3;
|
return vo;
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
logger = Logger.getLogger(Logger.LOGGER_DEFAULT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+14
-1
@@ -43,6 +43,7 @@ public class TypedCircuitBreakerManager implements Lifecycle {
|
|||||||
PrometheusMeterRegistry meterRegistry;
|
PrometheusMeterRegistry meterRegistry;
|
||||||
CircuitBreakerRegistry circuitBreakerRegistry;
|
CircuitBreakerRegistry circuitBreakerRegistry;
|
||||||
TypedCircuitBreakerVO defaultConfigVo;
|
TypedCircuitBreakerVO defaultConfigVo;
|
||||||
|
HashMap<String, TypedCircuitBreakerVO> idCBConfigMap = new HashMap<>();
|
||||||
HashMap<String, TypedCircuitBreakerVO> apiIdCBConfigMap = new HashMap<>();
|
HashMap<String, TypedCircuitBreakerVO> apiIdCBConfigMap = new HashMap<>();
|
||||||
HashMap<String, TypedCircuitBreakerVO> urlCBConfigMap = new HashMap<>();
|
HashMap<String, TypedCircuitBreakerVO> urlCBConfigMap = new HashMap<>();
|
||||||
private boolean started;
|
private boolean started;
|
||||||
@@ -109,11 +110,13 @@ public class TypedCircuitBreakerManager implements Lifecycle {
|
|||||||
for (TypedCircuitBreakerVO vo : circuitBreakerList) {
|
for (TypedCircuitBreakerVO vo : circuitBreakerList) {
|
||||||
if (!StringUtils.equalsIgnoreCase(vo.useYn, "1")) {
|
if (!StringUtils.equalsIgnoreCase(vo.useYn, "1")) {
|
||||||
this.apiIdCBConfigMap.remove(vo.getName());
|
this.apiIdCBConfigMap.remove(vo.getName());
|
||||||
|
this.idCBConfigMap.remove(vo.getId());
|
||||||
logger.info("init skip (useYn) - " + vo);
|
logger.info("init skip (useYn) - " + vo);
|
||||||
} else {
|
} else {
|
||||||
CircuitBreakerConfig circuitBreakerConfig = this.createCircuitBreakerConfig(vo);
|
CircuitBreakerConfig circuitBreakerConfig = this.createCircuitBreakerConfig(vo);
|
||||||
vo.setCircuitBreakerConfig(circuitBreakerConfig);
|
vo.setCircuitBreakerConfig(circuitBreakerConfig);
|
||||||
this.apiIdCBConfigMap.put(vo.getName(), vo);
|
this.apiIdCBConfigMap.put(vo.getName(), vo);
|
||||||
|
this.idCBConfigMap.remove(vo.getId(), vo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +159,17 @@ public class TypedCircuitBreakerManager implements Lifecycle {
|
|||||||
public void reload(String key) throws Exception {
|
public void reload(String key) throws Exception {
|
||||||
logger.info("reload start.");
|
logger.info("reload start.");
|
||||||
TypedCircuitBreakerVO vo = this.dao.get(key);
|
TypedCircuitBreakerVO vo = this.dao.get(key);
|
||||||
if (StringUtils.equalsIgnoreCase(vo.useYn, "0")) {
|
if(vo == null) {
|
||||||
|
vo = this.idCBConfigMap.get(key);
|
||||||
|
if(vo != null) {
|
||||||
|
this.idCBConfigMap.remove(key);
|
||||||
|
this.apiIdCBConfigMap.remove(vo.getName());
|
||||||
|
this.circuitBreakerRegistry.remove(vo.getName());
|
||||||
|
logger.info("removed. - " + vo);
|
||||||
|
} else {
|
||||||
|
logger.info("not exist in memory. - " + key);
|
||||||
|
}
|
||||||
|
} else if (StringUtils.equalsIgnoreCase(vo.useYn, "0")) {
|
||||||
this.apiIdCBConfigMap.remove(vo.getName());
|
this.apiIdCBConfigMap.remove(vo.getName());
|
||||||
this.circuitBreakerRegistry.remove(vo.getName());
|
this.circuitBreakerRegistry.remove(vo.getName());
|
||||||
logger.info("removed. - " + vo);
|
logger.info("removed. - " + vo);
|
||||||
|
|||||||
+1
@@ -11,6 +11,7 @@ import org.mapstruct.ReportingPolicy;
|
|||||||
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||||
public interface TypedCircuitBreakerMapper extends GenericMapper<TypedCircuitBreakerVO, CircuitBreakerConfig> {
|
public interface TypedCircuitBreakerMapper extends GenericMapper<TypedCircuitBreakerVO, CircuitBreakerConfig> {
|
||||||
@Mappings({
|
@Mappings({
|
||||||
|
@Mapping(source = "cbreakerId", target = "id"),
|
||||||
@Mapping(source = "cbreakerName", target = "name"),
|
@Mapping(source = "cbreakerName", target = "name"),
|
||||||
@Mapping(source = "cbreakerDesc", target = "desc"),
|
@Mapping(source = "cbreakerDesc", target = "desc"),
|
||||||
@Mapping(source = "cbreakerType", target = "type"),
|
@Mapping(source = "cbreakerType", target = "type"),
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
@Builder
|
@Builder
|
||||||
public class TypedCircuitBreakerVO {
|
public class TypedCircuitBreakerVO {
|
||||||
|
String id;
|
||||||
String type;
|
String type;
|
||||||
String name;
|
String name;
|
||||||
String desc;
|
String desc;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import com.eactive.eai.common.TransactionContextKeys;
|
import com.eactive.eai.common.TransactionContextKeys;
|
||||||
import com.eactive.eai.common.circuitBreaker.CircuitBreakerManager;
|
import com.eactive.eai.common.circuitBreaker.CircuitBreakerManager;
|
||||||
|
import com.eactive.eai.common.circuitBreaker.type.TypedCircuitBreakerManager;
|
||||||
import com.eactive.eai.message.StandardMessage;
|
import com.eactive.eai.message.StandardMessage;
|
||||||
import com.eactive.eai.util.PropertiesUtil;
|
import com.eactive.eai.util.PropertiesUtil;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
@@ -98,13 +99,20 @@ public class RESTProcess extends HTTPProcess {
|
|||||||
int iTimeoutValue = getTimeoutCodeToValue();
|
int iTimeoutValue = getTimeoutCodeToValue();
|
||||||
this.timeout = iTimeoutValue * 1000;
|
this.timeout = iTimeoutValue * 1000;
|
||||||
this.tempProp.put(INTERFACE_TIME_OUT, "" + this.timeout);
|
this.tempProp.put(INTERFACE_TIME_OUT, "" + this.timeout);
|
||||||
String circuitBreakerUseYn = PropManager.getInstance().getProperty("CircuitBreaker", "useYn");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ("Y".equals(circuitBreakerUseYn)) {
|
// API별 이용
|
||||||
String apiId = reqEaiMsg.getEAISvcCd();
|
String apiId = reqEaiMsg.getEAISvcCd();
|
||||||
CircuitBreaker circuitBreaker = CircuitBreakerManager.getInstance().getCircuitBreaker(apiId);
|
CircuitBreaker circuitBreaker = TypedCircuitBreakerManager.getInstance().getCircuitBreaker(apiId);
|
||||||
|
|
||||||
|
// 디폴트 이용
|
||||||
|
if(circuitBreaker == null) {
|
||||||
|
String circuitBreakerUseYn = PropManager.getInstance().getProperty("CircuitBreaker", "useYn");
|
||||||
|
if ("Y".equals(circuitBreakerUseYn))
|
||||||
|
circuitBreaker = CircuitBreakerManager.getInstance().getCircuitBreaker(apiId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (circuitBreaker != null) {
|
||||||
// ObjectMapper 인스턴스 생성
|
// ObjectMapper 인스턴스 생성
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
@@ -116,10 +124,7 @@ public class RESTProcess extends HTTPProcess {
|
|||||||
logger.info("CircuitBreaker state " + combinedNode.toString());
|
logger.info("CircuitBreaker state " + combinedNode.toString());
|
||||||
this.resObject = circuitBreaker.executeCallable(() -> HttpSender
|
this.resObject = circuitBreaker.executeCallable(() -> HttpSender
|
||||||
.callService(this.adapterGroupName, this.outboundProp, this.reqObject, this.tempProp));
|
.callService(this.adapterGroupName, this.outboundProp, this.reqObject, this.tempProp));
|
||||||
|
} else {
|
||||||
|
|
||||||
|
|
||||||
}else{
|
|
||||||
this.resObject = HttpSender.callService(this.adapterGroupName, this.outboundProp, this.reqObject, this.tempProp);
|
this.resObject = HttpSender.callService(this.adapterGroupName, this.outboundProp, this.reqObject, this.tempProp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user