Comments (9)
Please create a reproduction code.
from moleculer-channels.
// 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);
});
from moleculer-channels.
How to ensure that data in pending is not lost after destroying the service
from moleculer-channels.
@putty-kang
The default value for moleculer channels configuration for redis.startID is "$" which means pick up only new messages. You will need to store and manage this value if you want to pick up messages that may have come in while service was down.
From README documentation (https://github.com/moleculerjs/moleculer-channels)
Starting point when consumers fetch data from the consumer group. By default equals to $, i.e., consumers will only see new elements arriving in the stream. More info [here](https://redis.io/commands/XGROUP)
from moleculer-channels.
@valeeum I set startID is 0
from moleculer-channels.
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
from moleculer-channels.
You need to first check if there is a message in the ending, and then delete the corresponding consumer
from moleculer-channels.
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
);
}
from moleculer-channels.
Repro example and the proposed fix are here: 8c3eb6e
from moleculer-channels.
Related Issues (20)
- amqp failed to reconnect
- durable_name NATS option being overwritten. HOT 2
- Error using typescript HOT 3
- The NATS Channel adapter breaks when using wildcard topics HOT 5
- emitlLocalChannelHandler error when channel is defined with options
- How to dynamically add middleware within code? HOT 4
- Custom sendMethodName is not working, still defaulting to sendToChannel HOT 2
- sendToChannel middleware hook is not firing HOT 2
- benchmark sendToChannel vs emit HOT 3
- AMQP: DEAD_LETTER exchange needs to be asserted
- Redis Adapter Capped Stream Support - "MAXLEN ~" HOT 4
- Context should have channelName
- Loosing subscriber connection to Kafka HOT 1
- Documentation fails to mention required payload type with externally-published messages HOT 7
- Redis do not auto trim redis stream data HOT 1
- moleculer-channels redis adapter How to clear messages? HOT 1
- amqlib version warning HOT 2
- Error: Error while moving messages of test.handler-completed to test.channels-dead-letter
- MoleculerRetryableError: Adapter not yet connected. Skipping publishing
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moleculer-channels.