增加消息处理异常记录--system模块
This commit is contained in:
@@ -7,11 +7,6 @@ package com.njcn.mq.constant;
|
|||||||
*/
|
*/
|
||||||
public interface BusinessTopic {
|
public interface BusinessTopic {
|
||||||
|
|
||||||
/***
|
|
||||||
* 测试阶段用的用户主题
|
|
||||||
*/
|
|
||||||
String NJCJ_USER_TOPIC = "njcnUserTopic";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 治理主送推送数据接收主题
|
* 治理主送推送数据接收主题
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package com.njcn.mq.message;
|
|
||||||
|
|
||||||
import com.njcn.middle.rocket.domain.BaseMessage;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hongawen
|
|
||||||
* @version 1.0.0
|
|
||||||
* @date 2023年08月10日 14:45
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
public class UserMessage extends BaseMessage {
|
|
||||||
private String userName;
|
|
||||||
private LocalDate birthday;
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package com.njcn.mq.template;
|
|
||||||
|
|
||||||
import com.njcn.middle.rocket.template.RocketMQEnhanceTemplate;
|
|
||||||
import com.njcn.mq.constant.BusinessTopic;
|
|
||||||
import com.njcn.mq.message.UserMessage;
|
|
||||||
import org.apache.rocketmq.client.producer.SendResult;
|
|
||||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author hongawen
|
|
||||||
* @version 1.0.0
|
|
||||||
* @date 2023年08月10日 14:44
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class UserMessageTemplate extends RocketMQEnhanceTemplate {
|
|
||||||
|
|
||||||
|
|
||||||
public UserMessageTemplate(RocketMQTemplate template) {
|
|
||||||
super(template);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 入参只需要传入是哪个订单号和业务体消息即可,其他操作根据需要处理
|
|
||||||
* 这样对于调用者而言,可以更加简化调用
|
|
||||||
*/
|
|
||||||
public SendResult sendMember(String userName, LocalDate birthday) {
|
|
||||||
UserMessage message = new UserMessage();
|
|
||||||
message.setKey(UUID.randomUUID().toString());
|
|
||||||
message.setUserName(userName);
|
|
||||||
message.setBirthday(birthday);
|
|
||||||
return send(BusinessTopic.NJCJ_USER_TOPIC, "CREATE", message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package com.njcn.system.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||||
|
import com.njcn.common.pojo.constant.OperateType;
|
||||||
|
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||||
|
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||||
|
import com.njcn.common.pojo.response.HttpResult;
|
||||||
|
import com.njcn.common.utils.HttpResultUtil;
|
||||||
|
import com.njcn.common.utils.LogUtil;
|
||||||
|
import com.njcn.system.pojo.param.DictDataParam;
|
||||||
|
import com.njcn.system.pojo.po.RocketmqMsgErrorLog;
|
||||||
|
import com.njcn.system.service.IRocketmqMsgErrorLogService;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import com.njcn.web.controller.BaseController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* rocketmq消息处理记录表 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @since 2023-08-17
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/rocketmqMsgErrorLog")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class RocketmqMsgErrorLogController extends BaseController {
|
||||||
|
|
||||||
|
private final IRocketmqMsgErrorLogService rocketmqMsgErrorLogService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增消息异常记录
|
||||||
|
*
|
||||||
|
* @param rocketmqMsgErrorLog 消息异常数据
|
||||||
|
*/
|
||||||
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||||
|
@PostMapping("/add")
|
||||||
|
@ApiOperation("新增消息异常记录")
|
||||||
|
@ApiImplicitParam(name = "rocketmqMsgErrorLog", value = "消息异常数据", required = true)
|
||||||
|
public HttpResult<Object> add(@RequestBody RocketmqMsgErrorLog rocketmqMsgErrorLog) {
|
||||||
|
String methodDescribe = getMethodDescribe("add");
|
||||||
|
LogUtil.njcnDebug(log, "{},消息异常数据:{}", methodDescribe, rocketmqMsgErrorLog);
|
||||||
|
boolean result = rocketmqMsgErrorLogService.save(rocketmqMsgErrorLog);
|
||||||
|
if (result) {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||||
|
} else {
|
||||||
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.njcn.system.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.njcn.system.pojo.po.RocketmqMsgErrorLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* rocketmq消息处理记录表 Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @since 2023-08-17
|
||||||
|
*/
|
||||||
|
public interface RocketmqMsgErrorLogMapper extends BaseMapper<RocketmqMsgErrorLog> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.njcn.system.mapper.RocketmqMsgErrorLogMapper">
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.njcn.system.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.njcn.system.pojo.po.RocketmqMsgErrorLog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* rocketmq消息处理记录表 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @since 2023-08-17
|
||||||
|
*/
|
||||||
|
public interface IRocketmqMsgErrorLogService extends IService<RocketmqMsgErrorLog> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.njcn.system.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.system.mapper.RocketmqMsgErrorLogMapper;
|
||||||
|
import com.njcn.system.pojo.po.RocketmqMsgErrorLog;
|
||||||
|
import com.njcn.system.service.IRocketmqMsgErrorLogService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* rocketmq消息处理记录表 服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author hongawen
|
||||||
|
* @since 2023-08-17
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class RocketmqMsgErrorLogServiceImpl extends ServiceImpl<RocketmqMsgErrorLogMapper, RocketmqMsgErrorLog> implements IRocketmqMsgErrorLogService {
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user