-
Notifications
You must be signed in to change notification settings - Fork 15
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
Redis adapter #74
Comments
Please create a reproduction code. |
// static-service.js
const { ServiceBroker } = require("moleculer");
const ChannelsMiddleware = require("@moleculer/channels").Middleware;
const broker = new ServiceBroker({
namespace: "test",
nodeID: "test1",
transporter: "TCP",
middlewares:[ChannelsMiddleware({
adapter:"redis://127.0.0.1:6379"
})]
});
// Start the Moleculer broker
broker.start();
broker.repl();
setInterval(() => {
broker.sendToChannel("order.created", {
id: 1234,
items: "test"
});
}, 100);
// Start the service to serve static resources
const serviceSchema = {
name: "subscriber",
channels: {
"order.created": {
group: "mygroup",
redis: {
minIdleTime: 1000,
claimInterval: 1,
startID: "0"
},
maxRetries: 100,
handler(payload) {
console.log(payload);
throw new Error;
}
}
},
}
broker.createService(serviceSchema).then();
// send 10 times
broker.destroyService("subscriber").then(()=>{
setTimeout(()=>{
// then create new Service, Remaining transmission times data loss
broker.createService(serviceSchema);
}, 10000);
}); |
How to ensure that data in pending is not lost after destroying the service |
@putty-kang From README documentation (https://github.com/moleculerjs/moleculer-channels) |
@valeeum I set startID is 0 |
const pubClient = this.clients.get(this.pubName);
// 1. Delete consumer from the consumer group
// 2. Do NOT destroy the consumer group
// https://redis.io/commands/XGROUP
return pubClient.xgroup(
"DELCONSUMER",
chan.name, // Stream Name
chan.group, // Consumer Group
chan.id // Consumer ID
); ================================================================================ This code results in the loss of unconsumed messages in the reconnecting extension after the service is disconnected |
You need to first check if there is a message in the ending, and then delete the corresponding consumer |
const pubClient = this.clients.get(this.pubName);
let pending = await pubClient.xpending(
chan.name,
chan.group,
"-",
"+",
10 // Max reported entries
);
if(!pending) {
// 1. Delete consumer from the consumer group
// 2. Do NOT destroy the consumer group
// https://redis.io/commands/XGROUP
return pubClient.xgroup(
"DELCONSUMER",
chan.name, // Stream Name
chan.group, // Consumer Group
chan.id // Consumer ID
);
} |
Repro example and the proposed fix are here: 8c3eb6e |
Publish offline messages, simulate subscription exceptions, set to retry 100 times, and disconnect the subscription end when sending 10 times,
When the subscriber reconnects, the subsequent retry message cannot be received and the message is lost
The text was updated successfully, but these errors were encountered: