Closed miketran78727 closed 6 years ago
+1
exactly what I need! As we say here:"ça gère grave la fougère!"
Is this still open or part of neon ?
@seesiva You can check out the pull request. https://github.com/eclipse/paho.mqtt.javascript/pull/72 This is still under review.
The PR was merged in manually here: https://github.com/eclipse/paho.mqtt.javascript/commit/258524896c90139e55c9d26d9376e25536b6149d
@miketran78727 could you check that this new functionality works correctly in the develop branch before we close this off please? Just to make sure that my merge went properly :)
@jpwsutton Will do!
@jpwsutton Sorry James.. I have been busy with work in the last few weeks. I will find some gap this week to run my manual tests for the develop branch.
@jpwsutton Offline publishing does not work as expected,
My test expects the number of delivered messages = number of published messages
after successful reconnect
Messages sent: 57
Messages delivered: 41
I will look into the problem.
I forgot to set the offline publishing properties in the previous test:
client.disconnectedPublish = true;
client.disconnectedBufferSize = disconnectedBufferSize;
So, the code is working as expected. If reconnect = true
but client.disconnectedPublishing = false
, only automatic reconnect is enabled.
When can we expect this one to be released?
hy mike,
the application using node or native javascript?
+1
@jpwsutton how can I use this feature for auto-reconnect?
@miketran78727 @celalo
Is this feature available now?
@gautam-bmdi when I use it , test error. I not found it on master . come back to use mqtt.js
Automatic Reconnect and Disconnected Publishing Plan
Currently, the Paho JavaScript client is lacking two major areas of functionality: Automatic Reconnect and Disconnected (or Offline) Publishing.
The goal is to implement these features in time for the next release Neon.
This issue aims to outline the plan for adding this new functionality into the JavaScript client. The design and implementation will be closely matched to the Java client's plan
Recap: Possible Client States
There are 5 main potential states that the client can be in. The User will usually desire the client to either be in the
connected
ordisconnected
states.never connected
: This is the initial state of the client where:connecting
: A connect request is in progress.connected
: The client is connected and ready to send and receive messages.disconnecting
: A disconnect request is in progress.disconnected
: The client goes from connected to disconnected state when:What does it do?
Automatic Reconnect
Will automatically attempt to reconnect to the broker (or one of the servers in the host list) while the client is in
disconnected
state.disconnected
state.connectionLost
callback is called before the client starts the reconnect process. Since the state of the client isdisconnected
, the application is allowed to call theconnect
function with new connection options if they wish.disconnect
is called whileconnected
, the client goes to thedisconnected
state and automatic reconnect is disabled.connect
after it had reconnected, an invalid state error will be thrown.Disconnected Publishing
Will allow the client to save messages in a buffer whilst the client is in the
disconnected
state.never connected
state. So it cannot send any messages before it connects for the first time.disconnect
is called whileconnected
, the client goes todisconnected
state and Disconnected Publishing remains active if enabled.API Changes
Automatic Reconnect
The following optional attributes will be added to the Connection Options object:
reconnect
: boolean. If present andTrue
, the client will attempt to reconnectreconnectInterval
: number. Time interval in seconds between connect attempts. Default: 10 (seconds).The following new callback will be added:
onConnect
- called when the connection is established. A response object is passed to theonConnect
callback containing the following fields:reconnect
- boolean.True
if the connection is the result of a reconnect operationuri
- string. Fully qualified WebSocket URI of the serverThe existing
onConnectionLost
callback will be changed as follows:onConnectionLost
- called when a connection has been lost. A single response object parameter is passed to theonConnectionLost
callback containing the following fields:errorCode
- number.errorMessage
- string.reconnect
: boolean. If present andTrue
, the client will perform automatic reconnection while it isdisconnected
.Disconnected Publishing
The following optional attributes will be added to the Messaging Client object:
disconnectedPublishing
: boolean. If present andTrue
, the client will save messages while it isdisconnected
. This attribute is independent from thereconnect
attribute mentioned above. Thus the application can set this flag to buffer messages and try to reconnect at a later time.disconnectedBufferSize
: number. The maximum number of messages that will be stored in memory while the client isdisconnected
. Default : 5000deleteOldestBufferedMessages
: boolean. If present andTrue
, the client will delete oldest messages in the buffer to make room for newer messages.persistDisconnectedBuffer
: boolean. If present anTrue
, the client will persist the buffered messages.persistDisconnectedBuffer
is not present orFalse
, the client will save messages in memory.bufferedMessages
: number. This read-only attribute is the number of buffered messages.The following methods will be added:
New Error
When the buffer is full and deleteOldestBufferedMessages is not present or False, the following error will be thrown:
errorCode
: 18errorMessage
: AMQJS0018E Message buffer is full, maximum buffer size: ${0}.Sample application
This application wants to use both Automatic Reconnect and Disconnected Publising. The Application does not want to persist buffered messages.