Java Eclipse Paho Implementation - Auto reconnect

后端 未结 3 492
不知归路
不知归路 2021-01-05 01:41

I\'m trying to implement eclipse.paho in my project to connect Mqtt Broker (Both subscribing and publishing purpose). The problem is, when I using the subscribi

3条回答
  •  情歌与酒
    2021-01-05 02:24

    To use auto reconnect, just set setAutomaticReconnect(true) on the MqttConnectOptions object.

    MqttAndroidClient mqttClient = new MqttAndroidClient(context, mqttUrl, clientId);
    
    MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
    mqttConnectOptions.setAutomaticReconnect(true);
    
    mqttClient.connect(mqttConnectOptions, null, mqttActionListener());
    

提交回复
热议问题