rabbitmq-tt
v0.0.1
Published
Rabbitmq lib
Downloads
5
Readme
Cài module:
$ npm install --save rabbitmq-tt
Sử dụng module
import {Rpc, Publisher, WorkerManager, ExchangeManager} from 'rabbitmq-tt';
Rpc
import {Rpc} from 'rabbitmq-tt';
var rpc = Rpc('amqp://username:password@host/vhost', {timeout: 10000});
// Rpc client
var client = rpc.client();
setInterval(function() {
let request = client.request('hello', {test: 1});
request.then(data => {
console.log(data);
}).catch(e =>{
console.log(e);
});
}, 1000);
// Rpc server
var server = rpc.server();
server.on('hello', function(data, callback) {
console.log('server todo', data);
callback(null, {a: 'Hi'});
});
Publish to worker
import {Publisher} from 'rabbitmq-tt';
var publisher = Publisher('amqp://username:password@host/vhost');
var nb = 0;
setInterval(function() {
publisher.publish('', 'queuename', {number: nb++});
}, 100);
Worker
import {WorkerManager} from 'rabbitmq-tt';
var workerManager = WorkerManager('amqp://username:password@host/vhost');
const handle = (params, callback) => {
console.log(params);
setTimeout(function() {
callback();
}, 0);
};
workerManager.addWorker('queuename', handle);