Browse Source

报警消息不再重复入列

lixing 2 years ago
parent
commit
739dc9d7b7

+ 2 - 1
AlarmEngineStarter/pom.xml

@@ -10,6 +10,7 @@
     <modelVersion>4.0.0</modelVersion>
 
     <artifactId>alarm-engine-starter</artifactId>
+    <version>v2.0.1-SNAPSHOT</version>
 
     <properties>
         <maven.compiler.source>8</maven.compiler.source>
@@ -85,7 +86,7 @@
         <dependency>
             <groupId>com.persagy</groupId>
             <artifactId>apm-common</artifactId>
-            <version>v1.0.0</version>
+            <version>v1.2.0-SNAPSHOT</version>
         </dependency>
 
     </dependencies>

+ 4 - 4
AlarmEngineStarter/src/main/java/com/persagy/apm/energyalarmstarter/alarmengine/jms/JmsConfig.java

@@ -220,9 +220,9 @@ public class JmsConfig {
             JSONObject data = msg.getExts();
             redisUtil.unlock(alarmRecordLockPrefix + data.getString("id"));
         } catch (Exception e) {
-            log.error("报警记录消息消费失败", e);
-            // 消息扔回消息队列
-            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
+            log.error("报警记录消息消费失败, 消息为:{}", msg, e);
+            // 拒绝消息,requeue=false 表示不再重新入队,如果配置了死信队列则进入死信队列
+            channel.basicReject(message.getMessageProperties().getDeliveryTag(), false);
         }
 
     }
@@ -247,7 +247,7 @@ public class JmsConfig {
                     log.error("error", e);
                 }
             }
-            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
+            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
         } catch (Exception e) {
             log.error("消息消费失败", e);
         }

+ 3 - 0
readme.md

@@ -0,0 +1,3 @@
+# v2.0.1
+
+1. 报警消息的消费不再无限次的重试,而是在重试一次失败后直接丢弃,同时在日志中打印消费失败的消息及消费失败的原因