emq断连不稳定,重连订阅主题失败

环境信息

  • EMQ X 版本:4.3.6

  • 操作系统及版本:CentOS Linux release 7.9.2009 (Core)

  • 其他
    报错信息

2021-08-03 22:44:49.721 [MQTT Call: personnel-service-1311-t] INFO  com.znv.personnel.mqtt.common.MqttClientConfig - emq重连成功,是否是重连:true,服务地址:ws://

2021-08-03 22:46:49.726 [MQTT Ping: personnel-service-1311-t] ERROR o.eclipse.paho.client.mqttv3.internal.ClientState - personnel-service-1311-t: Timed out as no activity, keepAlive=60,000,000,000 lastOutboundActivity=19,838,129,920,573,717 lastInboundActivity=19,838,069,923,407,383 time=19,838,189,920,445,703 lastPing=19,838,129,920,589,493

2021-08-03 22:46:49.730 [MQTT Ping: personnel-service-1311-t] WARN  com.znv.personnel.mqtt.common.MqttClientConfig - emq连接断开,msg:Timed out waiting for a response from the server (32000)

2021-08-03 22:46:49.730 [MQTT Call: personnel-service-1311-t] ERROR com.znv.personnel.mqtt.common.MqttRegistry - 订阅emq主题失败,主题:ganges-data-door-event,主题监听beanName:personnnelPassCallback

org.eclipse.paho.client.mqttv3.MqttException: Timed out waiting for a response from the server

	at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)

	at org.eclipse.paho.client.mqttv3.internal.ClientState.checkForActivity(ClientState.java:742)

	at org.eclipse.paho.client.mqttv3.internal.ClientComms.checkForActivity(ClientComms.java:816)

	at org.eclipse.paho.client.mqttv3.internal.ClientComms.checkForActivity(ClientComms.java:802)

	at org.eclipse.paho.client.mqttv3.TimerPingSender$PingTask.run(TimerPingSender.java:79)

	at java.util.TimerThread.mainLoop(Timer.java:555)

	at java.util.TimerThread.run(Timer.java:505)

问题描述

线上emq服务器在运行一段时间后会发生断连现象,并且重连成功但订阅主题失败
(这里重连后失败我看日志是因为重连以后又立刻断开了,导致订阅主题失败)
本地测试重连订阅主题没有问题

配置文件及日志

配置文件:
设置的参数:
image

线上断连报错:

然后顺着错误追到了源码:

错误是在这里抛出的
很是不解,本地没有这个问题 ,到线上就出现了
这个错误到底是什么原因导致的呢

是不是有clientid重复的情况?一连接上就被挤下来。

应该不是这个问题 我看报错是在检查服务器心跳出的问题

2021-08-03 00:02:05,438 [MQTT Ping: personnel-service-1311-t] ERROR o.eclipse.paho.client.mqttv3.internal.ClientState - personnel-service-1311-t: Timed out as no activity, keepAlive=60,000,000,000 lastOutboundActivity=19,756,245,632,609,452 lastInboundActivity=19,756,185,403,194,329 time=19,756,305,632,492,611 lastPing=19,756,245,632,612,457
2021-08-03 00:02:05,441 [MQTT Ping: personnel-service-1311-t] WARN  com.znv.personnel.mqtt.common.MqttClientConfig - emq连接断开,msg:Timed out waiting for a response from the server (32000)
2021-08-03 00:02:05,442 [MQTT Call: personnel-service-1311-t] ERROR com.znv.personnel.mqtt.common.MqttRegistry - 订阅emq主题失败,主题:ganges-access-door-auth-ack,主题监听beanName:doorAuthAckSubscribe
org.eclipse.paho.client.mqttv3.MqttException: Timed out waiting for a response from the server
	at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:31)
	at org.eclipse.paho.client.mqttv3.internal.ClientState.checkForActivity(ClientState.java:742)
	at org.eclipse.paho.client.mqttv3.internal.ClientComms.checkForActivity(ClientComms.java:816)
	at org.eclipse.paho.client.mqttv3.internal.ClientComms.checkForActivity(ClientComms.java:802)
	at org.eclipse.paho.client.mqttv3.TimerPingSender$PingTask.run(TimerPingSender.java:79)
	at java.util.TimerThread.mainLoop(Timer.java:555)
	at java.util.TimerThread.run(Timer.java:505)

这里面的Timed out as no activity, keepAlive=60,000,000,000 lastOutboundActivity=19,756,245,632,609,452 lastInboundActivity=19,756,185,403,194,329 time=19,756,305,632,492,611 lastPing=19,756,245,632,612,457
在源码中的


满足if条件 抛出异常了

看到你客户端连接代码中没设置keepalive时间,是不是这个原因?

这个参数我看源码里面默认值是60s 一般应该设置多少呢

如果默认60s的话应该没有问题

项目已经换成kafka了 后面发现如果飞行窗口和离线队列消息满了以后,不清楚会话,断开重连,会阻塞在订阅主题那里

@lixiangdao10 同样的问题, 解决了吗?

我们也遇见这样的问题,请问解决了吗?

我们也遇见了这个问题

请问解决了吗

这个应该是 paho 那边的老问题,可以看看他们的 github issue ClientState: C5180518000011: Timed out as no activity, keepAlive=60,000 lastOutboundActivity=1,534,923,567,979 lastInboundActivity=1,534,923,507,945 time=1,534,923,627,951 lastPing=1,534,923,567,979 · Issue #576 · eclipse/paho.mqtt.java · GitHub

您好,这个问题解决了吗?我看着在issues上的问题,paho好像是并没有解决呢?

可以看看社区同学在这里的分享的调查结果 关于 Paho Mqtt Java 偶尔出现 checkForActivity Timed out as no activity 情况的排查