You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code below permanently blocks when using connectAsync and the MQTT server is not running.
The catch handler is not being triggered. How do I correctly use connectAsync so that after a connect timeout period an error is caught and notified to the user??
I am calling connectAsync with the following arguments:
/** * Publish a message to the mqtt broker for a given topic * Disposes the client connection upon send success or failure. * @param {string} topic - topic to publish to * @param {Object} message - message to publish */asyncpublish(topic,message){letclient=undefined;try{console.log('MQTTClient awaiting connection to broker for publishing...');client=awaitmqtt.connectAsync(this.#url,this.#options);console.log('MQTTClient acquired connection, publishing...');awaitclient.publish(topic,message,this.#options);console.log(`Published message to topic := ${topic}`);}catch(e){console.error(`Failed to publish message to topic := ${topic}`);console.error(`message := ${e.message}`);console.error(`stack := ${e.stack}`);}finally{console.log('MQTTClient closing connection');if(client)awaitclient.end();}}
Edit: Ahhh just looked at the source code. If I include an additional argument allowRetries to false then the catch handler triggers. So, if the allowRetries argument is not included then the default behaviour is that the client will continuously try to connect and code will block permanently until it is reconnected? Is my understanding correct?
Is there any option to specify the number of retries before a connection is deemed to have failed?
The text was updated successfully, but these errors were encountered:
Hi,
The following code below permanently blocks when using connectAsync and the MQTT server is not running.
The catch handler is not being triggered. How do I correctly use
connectAsync
so that after a connect timeout period an error is caught and notified to the user??I am calling connectAsync with the following arguments:
ca: /path/to/ca/file
rejectUnauthorised: true
}
Edit: Ahhh just looked at the source code. If I include an additional argument
allowRetries
to false then the catch handler triggers. So, if theallowRetries
argument is not included then the default behaviour is that the client will continuously try to connect and code will block permanently until it is reconnected? Is my understanding correct?Is there any option to specify the number of retries before a connection is deemed to have failed?
The text was updated successfully, but these errors were encountered: