A [Seneca.js][] plugin
![]() |
This open source module is sponsored and supported by Voxgig. |
|---|
npm install --save seneca-amqp-transportThis transport supports AMQP 0-9-1, which is what [amqplib][3] currently supports. For an AMQP 1.0 compliant transport, take a look at [seneca-servicebus-transport][8]
require('seneca')()
.use('seneca-amqp-transport')
.listen({ type: 'amqp', pin: 'role:create' })See test/ for usage examples.
This plugin provides AMQP transport for Seneca microservice messages using RabbitMQ.
If you're using this module and need help, you can:
- Post a [github issue][]
- Tweet to [@senecajs][]
The JSON object in defaults.json describes the available options for this transport. These are applicable to both clients and listeners.
To override this settings, pass them to the plugin's .use declaration:
require('seneca')()
.use('seneca-amqp-transport', {
amqp: {
client: {
queues: {
options: {
durable: false
}
}
}
}
});AMQP related options may be indicated either by the connection URI or by passing additional parameters to the seneca#client() or seneca#listen() functions.
This,
require('seneca')()
.use('seneca-amqp-transport')
.client({
type: 'amqp',
url: 'amqp://guest:guest@rabbitmq.host:5672/seneca?locale=es_AR'
});will result in the same connection URI as:
require('seneca')()
.use('seneca-amqp-transport')
.client({
type: 'amqp',
hostname: 'rabbitmq.host',
port: 5672,
vhost: 'seneca',
locale: 'es_AR',
username: 'guest',
password: 'guest'
});You may also pass in additional options for the channel#publish and channel#consume methods of [amqplib][3] under publish and consume, respectively.
require('seneca')()
.use('seneca-amqp-transport')
.client({
type: 'amqp',
hostname: 'rabbitmq.host',
publish: {
persistent: true
}
});Read the offical [amqplib][3] docs for a list of available options for
publishandconsume.
Additionally, you may pass in options to the amqp.connect method of [amqplib][3] as documented in [its API reference][4], using the socketOptions parameter.
// Example of using a TLS/SSL connection. Note that the server must be
// configured to accept SSL connections; see http://www.rabbitmq.com/ssl.html.
const fs = require('fs');
const opts = {
cert: fs.readFileSync('../etc/client/cert.pem'),
key: fs.readFileSync('../etc/client/key.pem'),
// cert and key or
// pfx: fs.readFileSync('../etc/client/keycert.p12'),
passphrase: 'MySecretPassword',
ca: [fs.readFileSync('../etc/testca/cacert.pem')]
};
require('seneca')()
.use('seneca-amqp-transport')
.client({
type: 'amqp',
url: 'amqp://guest:guest@rabbitmq.host:5672/seneca?locale=es_AR',
socketOptions: opts
});Snippet above is based on [amqplib/examples/ssl.js][5]
The [Senecajs org][] encourages open participation. If you feel you can help in any way, be it with documentation, examples, extra testing, or new features please get in touch.
npm run testUses the amqplib driver.
[1]: http://senecajs.org/
[2]: https://www.amqp.org/
[3]: https://github.com/squaremo/amqp.node
[4]: http://www.squaremobius.net/amqp.node/channel_api.html#connect
[5]: https://github.com/squaremo/amqp.node/blob/master/examples/ssl.js
[6]: https://www.rabbitmq.com/semantics.html
[7]: https://www.rabbitmq.com/tutorials/tutorial-six-javascript.html
[8]: https://github.com/otaviosoares/seneca-servicebus-transport
[9]: https://github.com/senecajs/seneca-amqp-transport/issues/new
[10]: https://github.com/senecajs/seneca-amqp-transport/pulls
[11]: http://senecajs.org/contribute/
[12]: ./LICENSE.md
[13]: https://github.com/senecajs/seneca-amqp-transport/wiki/2.1.0-migration-guide

