Reconnect #497
-
This is blowing my mind... how can I disable A simple connection option would be nice e.g. .withConnectProperties({ clientId, keepAliveIntervalSeconds, reconnect: false }); I think it's quite common that if the initial connection fails... it's going to fail again. No point in retrying in that case. For an already established connection it is a valid use case to reconnect. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The 311 client took that approach and, over time, we came to consider that a significant mistake. Using such an approach can be an unpleasant surprise, is more complicated, and forces everyone to wrap their connection attempt with retry logic. MQTT the protocol is oriented towards networking situations with unpredictable/unreliable connectivity. Any correct application has to retry since otherwise the application just fails if connectivity is down at launch. The metaphor for the 5 client is a light switch or circuit. If the switch is off (client stopped) nothing happens. If the switch is on (client started) then, if there's power (a route to the broker) you will have light (can perform MQTT operations). Power can come and go unpredictably, but the behavior of the switch being on/off remains fixed regardless of context (first attempt vs. nth attempt, etc...) If you truly want to disable reconnect, you can call stop() in reaction to a connection failed event. |
Beta Was this translation helpful? Give feedback.
The 311 client took that approach and, over time, we came to consider that a significant mistake. Using such an approach can be an unpleasant surprise, is more complicated, and forces everyone to wrap their connection attempt with retry logic.
MQTT the protocol is oriented towards networking situations with unpredictable/unreliable connectivity. Any correct application has to retry since otherwise the application just fails if connectivity is down at launch.
The metaphor for the 5 client is a light switch or circuit. If the switch is off (client stopped) nothing happens. If the switch is on (client started) then, if there's power (a route to the broker) you will have light (can perform MQ…