初始化项目
This commit is contained in:
36
xtools-app-common/xtools-app-common-mq/pom.xml
Normal file
36
xtools-app-common/xtools-app-common-mq/pom.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-app-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<artifactId>xtools-app-common-mq</artifactId>
|
||||
|
||||
<!-- 依赖 -->
|
||||
<dependencies>
|
||||
<!-- xtools begin -->
|
||||
<!-- xtools-boot-mq-base -->
|
||||
<dependency>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-boot-mq-base</artifactId>
|
||||
</dependency>
|
||||
<!-- xtools-boot-mq-rabbit -->
|
||||
<dependency>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-boot-mq-rabbit</artifactId>
|
||||
</dependency>
|
||||
<!-- xtools end -->
|
||||
|
||||
<!-- 项目模块 begin -->
|
||||
<dependency>
|
||||
<groupId>org.xujun</groupId>
|
||||
<artifactId>xtools-app-common-cache</artifactId>
|
||||
</dependency>
|
||||
<!-- 项目模块 end -->
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,65 @@
|
||||
package xtools.app.common.mq.enums;
|
||||
|
||||
import xtools.boot.mq.base.enums.MqEnums;
|
||||
|
||||
/**
|
||||
* <p>Title : RabbitMqEnums</p>
|
||||
* <p>Description : RabbitMqEnums</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 1.0.0
|
||||
* @date : 2026/2/5 16:46
|
||||
*/
|
||||
public enum RabbitMqEnums implements MqEnums {
|
||||
|
||||
// 系统日志
|
||||
SYS_LOG("sys.log", false),
|
||||
// 系统任务
|
||||
SYS_TASK("sys.task", true),
|
||||
;
|
||||
|
||||
/**
|
||||
* 队列名称
|
||||
*/
|
||||
private final String queue;
|
||||
|
||||
/**
|
||||
* 是否保存日志
|
||||
*/
|
||||
private final boolean saveLog;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
*
|
||||
* @param queue 队列名称
|
||||
* @param saveLog 是否保存日志
|
||||
*/
|
||||
RabbitMqEnums(String queue, boolean saveLog) {
|
||||
this.queue = queue;
|
||||
this.saveLog = saveLog;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取队列名称
|
||||
*
|
||||
* @return 队列名称
|
||||
*/
|
||||
@Override
|
||||
public String queue() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否保存日志
|
||||
*
|
||||
* @return 是否保存日志
|
||||
*/
|
||||
@Override
|
||||
public boolean saveLog() {
|
||||
return saveLog;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package xtools.app.common.mq.handle;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xtools.app.common.cache.enums.AppCache;
|
||||
import xtools.base.config.BaseParams;
|
||||
import xtools.boot.cache.redis.base.RedisService;
|
||||
import xtools.boot.mq.base.handle.BaseErrorHandle;
|
||||
import xtools.extend.encrypt.Sm3Utils;
|
||||
|
||||
/**
|
||||
* <p>Title : MqErrorHandle</p>
|
||||
* <p>Description : MqErrorHandle</p>
|
||||
* <p>DevelopTools : Idea_x64_v2026.1</p>
|
||||
* <p>DevelopSystem : macOS Sequoia 15.7.5</p>
|
||||
* <p>Company : org.xujun</p>
|
||||
*
|
||||
* @author : XuJun
|
||||
* @version : 1.0.0
|
||||
* @date : 2026/2/12 10:53
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MqErrorHandle implements BaseErrorHandle, BaseParams {
|
||||
|
||||
/**
|
||||
* 缓存参数
|
||||
*/
|
||||
private static final AppCache CACHE_PARAM = AppCache.MQ_MSG_ERR_COUNT;
|
||||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 消息处理错误异常(需要消息队列重推消息,抛出异常即可)
|
||||
*
|
||||
* @param message 消息内容
|
||||
* @param exception 异常信息
|
||||
*/
|
||||
@Override
|
||||
public void messageHandle(String message, Exception exception) {
|
||||
String cacheKey = CACHE_PARAM.key() + Sm3Utils.encryptToString(message);
|
||||
Long incr = redisService.incr(cacheKey);
|
||||
redisService.expire(cacheKey, CACHE_PARAM.expireTime());
|
||||
if (incr >= CP_NUM3) {
|
||||
redisService.del(cacheKey);
|
||||
} else {
|
||||
try {
|
||||
Thread.sleep(CP_NUM1000);
|
||||
} catch (InterruptedException e) {
|
||||
log.error("消息处理异常,等待失败", e);
|
||||
}
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user