我使用Android MQTT Paho客户端发送带有QoS 2的消息。 如果禁用设备上的网络并在启用网络时发送,如何保存消息?
mClient = new MqttAndroidClient(this, uri, clientId, new MqttDefaultFilePersistence());
MqttConnectOptions conOpt = new MqttConnectOptions();
conOpt.setMqttVersion(MqttConnectOptions.MQTT_VERSION_3_1);
conOpt.setCleanSession(true);
conOpt.setAutomaticReconnect(true);
mClient.setTraceEnabled(true);
mClient.setCallback(this);
mClient.setTraceCallback(this);
IMqttToken connectToken = mClient.connect(conOpt, null, this);
离线缓冲选项:
@Override
public void onSuccess(IMqttToken iMqttToken) {
this.disconnectedBufferOptions = new DisconnectedBufferOptions();
this.disconnectedBufferOptions.setBufferEnabled(true);
mClient.setBufferOpts(disconnectedBufferOptions);
subscribe(topic);
}
如果网络可用,则发布到主题的消息,但是如果它已禁用并再次启用离线消息而不是发送。