redis-streams-broker
This simple package is based on redis streams data type which provides you with following features
- Centeralized 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) {
console.log("Payload Id:", payload.id);
console.log("Payload Received from :", payload.channel);
console.log("Actual Payload:", payload.payload);
await payload.markAsRead();
}
const summary = await consumerGroup.pendingSummary();
const sucess = consumerGroup.unsubscribe(subscriptionHandle);
const consumedMem = await broker.memoryFootprint();
Built with
- Authors love for Open Source.
- IORedis.
Contributions
- New ideas/techniques are welcomed.
- Raise a Pull Request.
Current Version:
0.0.5[Beta]
License
This project is contrubution to public domain and completely free for use, view LICENSE.md file for details.