增加消息处理异常记录--system模块
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.njcn.system.api;
|
||||
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.system.api.fallback.RocketMqLogFeignClientFallbackFactory;
|
||||
import com.njcn.system.pojo.po.RocketmqMsgErrorLog;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0.0
|
||||
* @date 2023年08月18日 09:29
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.SYSTEM, path = "/rocketmqMsgErrorLog", fallbackFactory = RocketMqLogFeignClientFallbackFactory.class, contextId = "rocketmqMsgErrorLog")
|
||||
public interface RocketMqLogFeignClient {
|
||||
|
||||
@PostMapping("/add")
|
||||
HttpResult<Object> add(@RequestBody RocketmqMsgErrorLog rocketmqMsgErrorLog);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.njcn.system.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.system.api.RocketMqLogFeignClient;
|
||||
import com.njcn.system.pojo.po.RocketmqMsgErrorLog;
|
||||
import com.njcn.system.utils.SystemEnumUtil;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* @author denghuajun
|
||||
* @version 1.0.0
|
||||
* @date 2022年01月05日 15:08
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RocketMqLogFeignClientFallbackFactory implements FallbackFactory<RocketMqLogFeignClient> {
|
||||
|
||||
@Override
|
||||
public RocketMqLogFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
exceptionEnum = SystemEnumUtil.getExceptionEnum(businessException.getResult());
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new RocketMqLogFeignClient() {
|
||||
@Override
|
||||
public HttpResult<Object> add(RocketmqMsgErrorLog rocketmqMsgErrorLog) {
|
||||
log.error("{}异常,降级处理,异常为:{}", "保存消息异常数据", cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.njcn.system.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.bo.BaseEntity;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* rocketmq消息处理记录表
|
||||
* </p>
|
||||
*
|
||||
* @author hongawen
|
||||
* @since 2023-08-17
|
||||
*/
|
||||
@Data
|
||||
@TableName("rocketmq_msg_error_log")
|
||||
public class RocketmqMsgErrorLog{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* key
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 来源
|
||||
*/
|
||||
private String resource;
|
||||
|
||||
/**
|
||||
* 记录
|
||||
*/
|
||||
private String record;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user