This is a plugin to use RabbitMQ with Hemera.
RabbitMQ is a messaging broker - an intermediary for messaging. It gives your applications a common platform to send and receive messages, and your messages a safe place to live until received. It is complementary to the primary NATS transport system.
The client use JSON to transfer data.
Start a rabbitmq instance via docker-compose
docker-compose up
Visit http://127.0.0.1:15672 and log in with
Username: user
Password: user
const Hemera = require('nats-hemera')
const nats = require('nats').connect()
const hemera = new Hemera(nats, {
logLevel: 'info'
})
hemera.use(require('hemera-joi'))
// Topology & configuration via JSON look at https://github.com/arobson/rabbot
hemera.use(require('hemera-rabbitmq', { rabbot: options }))
- hemera-joi
The pattern is:
topic
: is the service name to publish torabbitmq
cmd
: is the command to executepublish
exchange
: the name of the exachangestring
options
: rabbot transport optionsobject
data
: the data to transferobject
Example:
hemera.act(
{
topic: 'rabbitmq',
cmd: 'publish',
exchange: 'pubsub',
options: {
type: 'MyMessage'
},
data: {
name: 'peter',
amount: 50
}
},
function() {}
)
The pattern is:
topic
: is the service name to publish torabbitmq
cmd
: is the command to executepublish
exchange
: the name of the exachangestring
options
: rabbot transport optionsobject
data
: the data to transferobject
Example:
hemera.act(
{
topic: 'rabbitmq',
cmd: 'request',
exchange: 'request',
options: {
type: 'MyRequest'
},
data: {
name: 'peter',
amount: 50
}
},
function() {}
)
Create a new rabbitmq subscriber which handles the interest on this subject and forward all messages with pub/sub semantic to the hemera service. You can define a pattern which represent the destination hemera service.
The interface is:
pattern
: the pattern which arrive hemeratype
: the typestring
Example:
hemera.rabbitmq.addPubSubProxy(
{
type: 'MyMessage'
pattern: {}
}
)
Create a new rabbitmq subscriber which handles the interest on this subject and forward all messages with request/reply semantic to the hemera service. You can define a pattern which represent the destination hemera service.
The interface is:
pattern
: the pattern which arrive hemeratype
: the typestring
Example:
hemera.rabbitmq.addRequestProxy(
{
type: 'MyMessage'
pattern: {}
}
)
The pattern is:
topic
: is a combination of the service name and the typerabbitmq.<type>
Example:
hemera.add(
{
topic: 'rabbitmq.MyMessage'
},
function(req, reply) {
// In case of pub / sub you can't reply
// In case of request / reply you can reply only with valid json
// In case of error or crash the message is redelivered
}
)