Messages being published without established connection to broker. What happens to the messages? #1609
Unanswered
manasatully
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
From reading the docs I see that
mqtt.Client
has this feature that automatically happens -start publishing before being connected
.In my code I am creating a connection using
myclient = mqtt.connect({...})
function. With the client that is received I have a call-back setup forconnect
andend
. I am reading messages from a queue and publishing them by callingmyclient.publish()
I see that the connection has not been established and the publish function is being called inside the for loop. I see that my for loop is not erroring out causing all messages in queue to be consumed. Since there does not exist a connection to the broker what would happen to the messages (since the client supports publishing messages to broker even before being connected)? Would they be sent when a connection is re-established/ I would lose the messages all together?
`
myclient = mqtt.connect({...});
myclient.on("connect", () => {
console.log('Connection established to broker');
});
myclient.on("error", (error: Error) => {
console.log(
Encountered error ${error}
);});
for (const message of messages) {
myclient.publish(mytopic, msg);
}
`
Beta Was this translation helpful? Give feedback.
All reactions