1.0.7 • Published 2 years ago

redis-msg-broker v1.0.7

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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
});	
1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.0

2 years ago