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