hannesa2 / paho.mqtt.android

Kotlin MQTT client for Android
415 stars 95 forks source link

Access to sessionPresent after automatic reconnect #43

Open fabianzwodrei opened 3 years ago

fabianzwodrei commented 3 years ago

Thanks for this fork and the maintenance.

I am testing a persistent connection between app and broker: I am using the sessionPresent flag after a successul connection to decide if a new subscription is necessary: If server acknowlegdes the connection and set the sessionPresent=true, the app wont need new subscriptions.

But I can't access the sessionPresent flag after a automatic reconnect, because the onSuccess-callback of my IMqttActionListeneris not called. Only the IMqttActionListener onSuccess-callback contains the token for that flag

Am I wrong with my concept of connection and subscription - or might it be useful to implement some sort of access to that sessionPresent flag during the reconnection?

hannesa2 commented 3 years ago

Hmm, is there a call onSuccess() missing ? Anyway, if you found a solution, I'm happy to approve the solution !

fabianzwodrei commented 3 years ago

The onSuccess Method of org.eclipse.paho.client.mqttv3 is called in case of a successful reconnect but there is only a MqttReconnectActionListener as a callback called but not the onSuccess of my IMqttActionListener

I debugged this loc: https://github.com/eclipse/paho.mqtt.java/blob/6f35dcb785597a6fd49091efe2dba47513939420/org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/ConnectActionListener.java#L87

My workaround at the moment is to disable automatic Reconnect. And to reestablish the connection after 3secs

fabianzwodrei commented 3 years ago

Note: The first connection made through MqttAndroidClient.connect(...) where I can set the callback to my callback, works perfectly. OnSuccess is called and I can access the sessionPresent comming from the broker server

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. Please comment here if it is still valid so that we can reprioritize. Thank you!