From 5fd53dcb8c0fb9acd9b9b40cf6f218eb0f713d13 Mon Sep 17 00:00:00 2001 From: linwl <304115325@qq.com> Date: Thu, 25 Feb 2021 11:08:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E6=95=B0=E7=BA=BF=E7=A8=8B=E5=A4=84?= =?UTF-8?q?=E7=90=86=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iotgateway/listener/IotMessageListener.java | 15 +++++---------- .../com/telpo/iotgateway/server/IotSubscribe.java | 10 +++++----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java b/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java index 87c066a..18f88ae 100644 --- a/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java +++ b/src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java @@ -1,15 +1,11 @@ package com.telpo.iotgateway.listener; -import com.google.common.base.Stopwatch; -import com.google.common.util.concurrent.ThreadFactoryBuilder; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.concurrent.BasicThreadFactory; -import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import javax.jms.Message; import javax.jms.MessageListener; -import javax.validation.constraints.Positive; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; @@ -37,7 +33,6 @@ public class IotMessageListener implements MessageListener { // task to run goes here log.warn("约1分钟处理 {} 个请求",count); count.getAndSet(0); - //System.out.println("Hello, stranger"); } }; @@ -48,7 +43,7 @@ public class IotMessageListener implements MessageListener { // 第二个参数为首次执行的延时时间,第三个参数为定时执行的间隔时间 // 10:秒 5:秒 // 第一次执行的时间为10秒,然后每隔五秒执行一次 - service.scheduleAtFixedRate(runnable, 60, 60, TimeUnit.SECONDS); + service.scheduleAtFixedRate(runnable, 120, 60, TimeUnit.SECONDS); } private ExecutorService executorService; @@ -80,10 +75,10 @@ public class IotMessageListener implements MessageListener { String content = new String(body); String topic = message.getStringProperty("topic"); String messageId = message.getStringProperty("messageId"); - log.info("receive message" - + ", topic = " + topic - + ", messageId = " + messageId - + ", content = " + content); +// log.info("receive message" +// + ", topic = " + topic +// + ", messageId = " + messageId +// + ", content = " + content); count.getAndIncrement(); } catch (Exception e) { diff --git a/src/main/java/com/telpo/iotgateway/server/IotSubscribe.java b/src/main/java/com/telpo/iotgateway/server/IotSubscribe.java index 5b9cc5e..19cdd32 100644 --- a/src/main/java/com/telpo/iotgateway/server/IotSubscribe.java +++ b/src/main/java/com/telpo/iotgateway/server/IotSubscribe.java @@ -104,20 +104,20 @@ public class IotSubscribe { Destination queue = (Destination)context.lookup("QUEUE"); // 创建连接。 - log.warn("Befor cf.createConnection"); + //log.warn("Befor cf.createConnection"); Connection connection = cf.createConnection(userInfo, password); - log.warn("Befor connection.addConnectionListener"); + //log.warn("Befor connection.addConnectionListener"); ((JmsConnection) connection).addConnectionListener(myJmsConnectionListener); // 创建会话。 // Session.CLIENT_ACKNOWLEDGE: 收到消息后,需要手动调用message.acknowledge()。 // Session.AUTO_ACKNOWLEDGE: SDK自动ACK(推荐)。 - log.warn("Befor connection.createSession"); + // log.warn("Befor connection.createSession"); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - log.debug("Befor connection.start"); + // log.debug("Befor connection.start"); connection.start(); // 创建Receiver连接。消费消息 - log.warn("Befor session.createConsumer"); + // log.warn("Befor session.createConsumer"); MessageConsumer consumer = session.createConsumer(queue); // 设置消息侦听