From 2df71cc50c932dc0af96e6a517a3834c19ee83e6 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Thu, 25 Feb 2021 09:10:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telpo/iotgateway/listener/IotMessageListener.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java b/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java index c02c0e4..b0ddc6e 100644 --- a/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java +++ b/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java @@ -19,7 +19,7 @@ import java.util.concurrent.ExecutorService; @Component public class IotMessageListener implements MessageListener { - int count = 0; + private static int count = 0; private ExecutorService executorService; public void setExecutorService(ExecutorService executorService) { @@ -33,11 +33,9 @@ public class IotMessageListener implements MessageListener { // 推荐做法:创建Session选择Session.AUTO_ACKNOWLEDGE,这里会自动ACK。 // 其他做法:创建Session选择Session.CLIENT_ACKNOWLEDGE,这里一定要调message.acknowledge()来ACK。 // message.acknowledge(); - //2.建议异步处理收到的消息,确保onMessage函数里没有耗时逻辑。 + //2.异步触发回调,处理收到的消息,确保onMessage函数里没有耗时逻辑。 // 如果业务处理耗时过程过长阻塞住线程,可能会影响SDK收到消息后的正常回调。 executorService.submit(() -> processMessage(message)); - count++; - log.info("count is : " + count); } catch (Exception e) { log.error("submit task occurs exception ", e); } @@ -56,6 +54,8 @@ public class IotMessageListener implements MessageListener { + ", topic = " + topic + ", messageId = " + messageId + ", content = " + content); + count++; + log.info("count is : " + count); } catch (Exception e) { log.error("processMessage occurs error ", e); }