Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Paho » Managing reconnections to MQTT server
Managing reconnections to MQTT server [message #1821631] Mon, 17 February 2020 21:17
column column is currently offline column columnFriend
Messages: 21
Registered: December 2017
Junior Member
Hello,

I do connect to MQTT server by using `MqttAndroidClient`:

    doReconnect()
    {
    .....
            mqttAndroidClient.connect(mqttConnectOptions, null,

                    new IMqttActionListener()
                    {

                        @Override
                        public void onSuccess(IMqttToken asyncActionToken)
                        {
                            Timber.tag(Utils.TIMBER_TAG).v( "onSuccess " + MqttHelper.toString(asyncActionToken));
                            DisconnectedBufferOptions disconnectedBufferOptions = new DisconnectedBufferOptions();
                            disconnectedBufferOptions.setBufferEnabled(false);
                            disconnectedBufferOptions.setBufferSize(100);
                            disconnectedBufferOptions.setPersistBuffer(false);
                            disconnectedBufferOptions.setDeleteOldestMessages(false);
                            mqttAndroidClient.setBufferOpts(disconnectedBufferOptions);
                            subscribeToTopic(top);

                            showMainActivity("Connect OK");

                        }

                        @Override
                        public void onFailure(IMqttToken asyncActionToken, Throwable e) {
                            Timber.tag(Utils.TIMBER_TAG).v( "Failed to connect to: " +uri+" "+e.toString());
                            showMainActivity("Failed while connect "+e.toString());

                            doReconnect()
                        }
                    });
    ....
    }


It works fine when server is available. Icase I close port I get `OnFailure` event which calls doReconnect again. If now I open port I will get two calls `onSuccess` instead of one and in MQTT server I see two subscribed clients. Looks like previous session is still trying to reconnect. Why I'm getting two calls and how to avoid it?


Previous Topic:paho c mqqt: TLS resumption settings
Next Topic:Can I trust MQTT when phone is in power safe mode
Goto Forum:
  


Current Time: Sun Oct 25 23:18:31 GMT 2020

Powered by FUDForum. Page generated in 0.02105 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top