Note that there are some explanatory texts on larger screens.

plurals
  1. POMQTT callback client Reconnection logic
    text
    copied!<p>I am unable to find a logic for reconnection of mqtt call back client. There is method onDisconnected() but I am unable to find documentation or any sample example on internet.</p> <p><strong>My Listener</strong></p> <p>public class MyListener implements Listener {</p> <pre><code> public MyListener() { } @Override public void onConnected() { System.out.println("Connected ...."); } @Override public void onDisconnected() { System.out.println("Disconnected"); } @Override public void onPublish(UTF8Buffer topic, Buffer body, Runnable ack) { System.out.println("Entered Onpublish"); try { System.out.println("received msg:" + msg); } catch (HikeException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally{ ack.run(); } } @Override public void onFailure(Throwable value) { value.printStackTrace(); } } </code></pre> <p><strong>Create Connection</strong></p> <pre><code>private void createConnection(String host, int port,String id, String token) throws Exception { this.disconnect(); MQTT mqtt = new MQTT(); mqtt.setHost(host, port); mqtt.setUserName(id); mqtt.setPassword(token); CallbackConnection callbackConnection = null; callbackConnection = mqtt.callbackConnection(); callbackConnection.listener(new MyListener()); callbackConnection.connect(new MyCallback&lt;Void&gt;("CONNECT")); callbackConnection.subscribe(new Topic[] { new Topic(uid + "/u", QoS.AT_MOST_ONCE) }, new MyCallback&lt;byte[]&gt;("EVENT SUBSCRIBE")); callbackConnection.subscribe(new Topic[] { new Topic(uid + "/s", QoS.AT_LEAST_ONCE), new Topic(uid + "/a", QoS.AT_LEAST_ONCE) }, new MyCallback&lt;byte[]&gt;("MSG SUBSCRIBE")); this.callbackConnection = callbackConnection; } </code></pre> <p><strong>MyCallback</strong></p> <pre><code>class MyCallback&lt;T&gt; implements Callback&lt;T&gt; { public MyCallback(String tag) { super(); this.tag = tag; } String tag; @Override public void onSuccess(T value) { System.out.println("TAG:" + tag + " =SUCCESS value=" + value); } @Override public void onFailure(Throwable value) { System.out.println("TAG:" + tag + "Fail"); value.printStackTrace(); } } </code></pre> <p>My question is how to implement mqtt reconnection to server logic ? If I should use onDisconnect() method, then how I can use it ?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload