redis-streams-broker
This simple package is based on redis streams data type which provides you with following features
- Centralized Que. (Using Redis)
- Guarantee of message delivery via consumer acknowledgements.
- Consumer Group functionality for scalability. (Just like Kafka)
Getting Started
- Install using
npm -i redis-streams-broker
- Require in your project.
const brokerType = require('redis-streams-broker').StreamChannelBroker;
- Run redis on local docker if required.
docker run --name streamz -p 6379:6379 -itd --rm redis:latest
- Instantiate with a redis connection and name for the stream.
const broker = new brokerType(redisConnectionString, name);
- All done, Start using it!!.
Examples/Code snippets
const redisConnectionString = "redis://127.0.0.1:6379/";
const qName = "Queue";
const brokerType = require('redis-streams-broker').StreamChannelBroker;
const broker = new brokerType(redisConnectionString, qName);
const payloadId = await broker.publish({ a: "Hello", b: "World" });
const consumerGroup = await broker.joinConsumerGroup("MyGroup");
const subscriptionHandle = await consumerGroup.subscribe("Consumer1", newMessageHandler);
async function newMessageHandler(payload) {
for (let index = 0; index < payload.length; index++) {
try {
const element = payload[index];
console.log("Payload Id:", element.id);
console.log("Payload Received from :", element.channel);
console.log("Actual Payload:", element.payload);
await element.markAsRead();
}
catch (exception) {
console.error(exception);
}
}
}
const summary = await consumerGroup.pendingSummary();
const sucess = consumerGroup.unsubscribe(subscriptionHandle);
const consumedMem = await broker.memoryFootprint();
Built with
- Authors love for Open Source.
- IORedis.
- shortid.
- redis-scripto.
Contributions
- New ideas/techniques are welcomed.
- Raise a Pull Request.
Current Version:
0.0.8[Beta]
License
This project is contrubution to public domain and completely free for use, view LICENSE.md file for details.