Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't not publish message after reconnect when I using mqtt-level-store with qos > 0 #1457

Closed
byterygon opened this issue Mar 22, 2022 · 2 comments

Comments

@byterygon
Copy link

byterygon commented Mar 22, 2022

Hey I'm new to mqttjs
I'm trying to use level store to persistence message while disconnect to the broker
here is my example code:

const mqtt = require("mqtt");
const levelStore = require("mqtt-level-store");
const manager = levelStore("./mqttMessage/");
const client = mqtt.connect("mqtt://127.0.0.1", {
  incomingStore: manager.incoming,
  outgoingStore: manager.outgoing,
});
client.on("connect", function () {
  client.subscribe("presence", function (err) {
    if (!err) {
    }
  });
});

client.on("message", function (topic, message) {
  debug(message.toString());
});

const debug2 = require("./src/utils/debug")("publish");
let i = 0;
setInterval(() => {
  debug2("sending message " + i);
  client.publish("presence", `${i}`, { qos: 2 }, (err) => {
    debug2(err || "sent " + i++);
  });
}, 3000);

here is the log:
image
I stop the broker after receive the 3rd (it's 4th but I will call it's 3rd to match the i value) message, after the interval triggered twice, I start the broker again
the 4th message that has been store is send completely,
The 5th message has been sent, but the subscriber could not receive any thing, you can see that the publish callback has been triggered and no err.
The 6th message, no message sent and the publish call back has not been triggered as you can see

Sorry for my English.

I'm using
"mqtt": "^4.3.6",
"mqtt-level-store": "^3.1.0",
"node": "^16.14.0"

@wanggaian
Copy link

wanggaian commented Sep 11, 2022

Hello, I also found this problem in the development of WeChat Mini Program. When I switch the program to the background and then switch back, it also hangs and does not receive the callback of publish. I expect to disconnect + reconnect (connect) to fix it, but still doesn't work.
Have you solved this problem now, and if so, what kind of solution did you take? Thank you very much

@byterygon
Copy link
Author

@wanggaian I have solved this problem by changing to nedb. I hope this may help you too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants