告警事件解析处理

This commit is contained in:
2023-11-08 16:16:26 +08:00
parent b33791e816
commit 277ca39dfc
8 changed files with 242 additions and 29 deletions

View File

@@ -0,0 +1,18 @@
package com.njcn.zlevent.api;
import com.njcn.common.pojo.constant.ServerInfo;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.mq.message.AppEventMessage;
import com.njcn.zlevent.api.fallback.AlarmClientFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
/**
* @author xy
*/
@FeignClient(value = ServerInfo.CS_ZL_EVENT_BOOT, path = "/alarm", fallbackFactory = AlarmClientFallbackFactory.class,contextId = "alarm")
public interface AlarmFeignClient {
@PostMapping("/analysis")
HttpResult<String> analysis(AppEventMessage appEventMessage);
}

View File

@@ -0,0 +1,35 @@
package com.njcn.zlevent.api.fallback;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.mq.message.AppEventMessage;
import com.njcn.zlevent.api.AlarmFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author xy
*/
@Slf4j
@Component
public class AlarmClientFallbackFactory implements FallbackFactory<AlarmFeignClient> {
@Override
public AlarmFeignClient create(Throwable cause) {
//判断抛出异常是否为解码器抛出的业务异常
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
if (cause.getCause() instanceof BusinessException) {
BusinessException businessException = (BusinessException) cause.getCause();
}
Enum<?> finalExceptionEnum = exceptionEnum;
return new AlarmFeignClient() {
@Override
public HttpResult<String> analysis(AppEventMessage appEventMessage) {
log.error("{}异常,降级处理,异常为:{}","告警数据解析",cause.toString());
throw new BusinessException(finalExceptionEnum);
}
};
}
}