Gathering detailed insights and metrics for @twilson63/palmetto-rmq
Gathering detailed insights and metrics for @twilson63/palmetto-rmq
Gathering detailed insights and metrics for @twilson63/palmetto-rmq
Gathering detailed insights and metrics for @twilson63/palmetto-rmq
npm install @twilson63/palmetto-rmq
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
This module uses rabbitMQ as the pub/sub messaging component for palmetto flow applications.
The default behavior works well if you want to have several subscribers that receive all messages.
Optional behavior is to utilize the roundRobin
option to distribute the message to the subscribers in a round-robin fashion.
In either configuration you can optionally provide a publishOnly
option. The returned instance will not receive any messages.
1var io = require('@twilson63/palmetto-rmq')({ 2 endpoint: 'amqp://guest:guest@localhost:5672', 3 app: '<appname>', 4 vhost: '<optional>' 5})
1io.on('foobar', function (msg) { 2 console.log(msg) 3})
1io.emit('send', msg)
1var uuid = uuid.v4() 2io.on(uuid, function (event) { 3 console.log(event.object) 4}) 5io.emit('send', { 6 to: 'widget.all.request', 7 from: uuid, 8 subject: 'widget', 9 verb: 'all', 10 type: 'request', 11 object: {} 12})
1io.on('widget.all.request', function (event) { 2 // do work 3 var results = ... 4 5 io.emit('send', { 6 to: event.from, 7 subject: 'widget', 8 verb: 'all', 9 type: 'response', 10 object: results 11 }) 12})
The service listens to the widget.all.request
svc then uses the from
node to publish the response to.
1//requestor-service.js 2 3var requestorIo = require('@twilson63/palmetto-rmq')({ 4 endpoint: 'amqp://guest:guest@localhost:5672', 5 app: '<requestorServiceName>', 6 vhost: '<optional>' 7}) 8 9var handlerIo = require('@twilson63/palmetto-rmq')({ 10 endpoint: 'amqp://guest:guest@localhost:5672', 11 app: '<handlerServiceName>', 12 vhost: '<optional>', 13 roundRobin: true, 14 publishOnly: true // only the 'handlerService' will listen for messages 15}) // this instance shouldn't participate in `roundRobin` consumption 16 17 18var uuid = uuid.v4() 19 20//setup response msg handler 21requestorIo.on(uuid, function (event) { 22 console.log(event.object) 23}) 24 25//send request msg 26handlerIo.emit('send', { 27 to: 'widget.all.request', 28 from: uuid, 29 subject: 'widget', 30 verb: 'all', 31 type: 'request', 32 object: {} 33})
1//handler-service.js 2//multiple instances of this service running 3 4var inboundIo = require('@twilson63/palmetto-rmq')({ 5 endpoint: 'amqp://guest:guest@localhost:5672', 6 app: '<handlerServiceName>', 7 vhost: '<optional>', 8 roundRobin: true, // all instances of 'handlerService' will get 'roundRobin' msg distribution 9 publishOnly: false // and obviously listen for those msgs 10}) 11 12var requestorIo = require('@twilson63/palmetto-rmq')({ 13 endpoint: 'amqp://guest:guest@localhost:5672', 14 app: '<requestorServiceName>', 15 vhost: '<optional>' 16}) 17 18 19//handle request messages 20inboundIo.on(uuid, function (event) { 21 22 doSomething(event.object) 23 .then(resultObject => { 24 25 requestorIo.emit('send', { 26 to: event.from, 27 from: event.to, 28 subject: event.subject + '-response', 29 verb: event.verb + '-response', 30 type: 'response', 31 object: resultObject 32 }) 33 34 }) 35 .catch(error => { 36 37 requestorIo.emit('send', { 38 to: event.from, 39 from: event.to, 40 subject: event.subject + '-error', 41 verb: event.verb + '-error', 42 type: 'response', 43 object: error 44 }) 45 46 }) 47}) 48 49
No vulnerabilities found.
No security vulnerabilities found.