林万龙 3 лет назад
Родитель
Сommit
2df71cc50c
1 измененных файлов: 4 добавлений и 4 удалений
  1. +4
    -4
      src/main/java/com/telpo/iotgateway/listener/IotMessageListener.java

+ 4
- 4
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);
}


Загрузка…
Отмена
Сохранить