public class MqttConnectionOptions {...// Automatic Reconnectprivate boolean automaticReconnect = false;// Time to wait before first automatic reconnection attempt in seconds.private int automaticReconnectMinDelay = 1;// Max time to wait for automatic reconnection attempts in seconds.private int automaticReconnectMaxDelay = 120;// Connection timeout in secondsprivate int connectionTimeout = 30;private int maxReconnectDelay = 128000;...}
struct MQTTAsync_connectOptions {.../*** The time interval in seconds to allow a connect to complete.*/int connectTimeout;/*** Reconnect automatically in the case of a connection being lost. 0=false, 1=true*/int automaticReconnect;/*** The minimum automatic reconnect retry interval in seconds. Doubled on each failed retry.*/int minRetryInterval;/*** The maximum automatic reconnect retry interval in seconds. The doubling stops here on failed retries.*/int maxRetryInterval;};
try (MqttClient client = new MqttClient(serverUri, clientId, new MemoryPersistence())) {MqttConnectOptions options = new MqttConnectOptions();options.setCleanSession(true);...client.setCallback(new MqttCallbackExtended() {@Overridepublic void connectComplete(boolean reconnect, String serverURI) {...try {// must resubscribeclient.subscribe(topicFilter, qos);} catch (MqttException e) {e.printStackTrace();}}...});client.connect(options);}
Feedback