redis-msg-broker

1.0.7 • Public • Published

In the name of ALLAH

This is a simple module that connecto to redis and handle publish and subscribe tasks.

How to use:

just import to your project and create an object like this:

const MsgBroker = require('redis-msg-broker').MsgBroker;
const msg_broker = new MsgBroker(); // have two optional arguments, first get a json object, secound get dev-status .

OR

const MsgBroker = require('redis-msg-broker').MsgBroker;
const msg_broker = new MsgBroker({host: "redis-server",port: 6379,db: 16},true);

OR

const MsgBroker = require('redis-msg-broker').MsgBroker;
const msg_broker = new MsgBroker({url: 'redis://redis:6379'}),true);				

MsgBroker have two async methods, publish and subscribe.

publish method get an argument {type: String, msg: json} like this example:

msg_broker.publish({type: "news", msg: {subject:"test subject", txt:"this just an example" } }).then((val)=>{console.log(val);}).catch((err)=>{console.log(err)});

subscribe method get an argument {type: String} and every time recive a message with wanted type, emit that msg as json obj, like this example:

msg_broker.subscribe({type: "news"}).then((val)=>{console.log(val);}).catch((err)=>{console.log(err)});

then for handling subscribed "news" we can do like this:

msg_broker.on('news', function (msg) {
	console.log("we recive this msg object ",msg); // msg is an json obj
});	

Readme

Keywords

Package Sidebar

Install

npm i redis-msg-broker

Weekly Downloads

8

Version

1.0.7

License

ISC

Unpacked Size

9.71 kB

Total Files

6

Last publish

Collaborators

  • miadian