Subscribe mqtt client when the display timeout. The second service may restart just fine, but may lose the message.
Given as follows
time out waiting for a response from the server: org.eclipse.paho.client.mqttv3.MqttException AT org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException (ExceptionHelper.java:31) ~ [org.eclipse.paho. client.mqttv3-1.2.1.jar /:! Na] AT org.eclipse.paho.client.mqttv3.internal.ClientState.checkForActivity (ClientState.java:741) ~ [org.eclipse.paho.client.mqttv3-1.2 .1.jar /:! Na] AT org.eclipse.paho.client.mqttv3.internal.ClientComms.checkForActivity (ClientComms.java:816) ~ [org.eclipse.paho.client.mqttv3-1.2.1.jar! /: Na] at org.eclipse.paho.client.mqttv3.internal.ClientComms.checkForActivity(ClientComms.java:802) ~[org.eclipse.paho.client.mqttv3-1.2.1.jar!/:na] AT org.eclipse.paho.client.mqttv3.TimerPingSender $ PingTask.run (TimerPingSender.java:79) ~ [org.eclipse.paho.client.mqttv3-1.2.1.jar /:! Na] AT java.util.TimerThread.mainLoop (Timer.java:555) ~ [na: 1.8.0_221] that java.util.TimerThread.run (Timer.java:505) ~ [na: 1.8.0_221]
Solution:
log.info ( "try connect to mqtt" );
// Call connect, must again call it token.waitForCompletion (); this should be on it. unknown reason.
IMqttToken token = client.connect(connOpts);
token.waitForCompletion();
log.info("connect mqtt success");
client.subscribe(topic, 1, new MqttMsgListener());