https://github.com/tableflip/svs-amqplib
Utilities for working with the amqplib
https://github.com/tableflip/svs-amqplib
Last synced: about 1 year ago
JSON representation
Utilities for working with the amqplib
- Host: GitHub
- URL: https://github.com/tableflip/svs-amqplib
- Owner: tableflip
- License: mit
- Created: 2015-02-21T11:35:50.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-02-21T13:30:37.000Z (over 11 years ago)
- Last Synced: 2025-02-15T12:46:44.758Z (over 1 year ago)
- Language: JavaScript
- Size: 141 KB
- Stars: 0
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# svs-amqplib
Utilities for working with the [amqplib](https://www.npmjs.org/package/amqplib).
## Example
```js
var amqp = require('svs-amqplib')(config.url)
/**
* Create a new amqp connection and create a new channel
* Subsequent calls to amqp.getChannel will return the same channel
* (No new connection, unless connection is disconnected)
*/
amqp.getChannel(function (er, chan) {
// `chan` is a amqplib channel
})
/**
* Create a new amqp connection and create a new _confirm_ channel
* Subsequent calls to amqp.getConfirmChannel will return the same channel
* (No new connection, unless connection is disconnected)
*/
amqp.getConfirmChannel(function (er, chan) {
// `chan` is an amqplib confirm channel
})
/**
* Ensure a persistent connection to the amqp server
* setupChannel called initially and on every disconnect
* setupChannel should connect, setup and return a channel
* customise timeout between re-connection retries
*/
amqp.reconnect('ID', setupChannel, {retryTimeout: 5000}, function (er, rc) {
console.log('Connected')
// In the future you can call rc.stop() to stop trying to reconnect
})
function setupChannel (cb) {
amqp.getChannel(function (er, chan) {
chan.assertQueue('queue', {}, function (er) {
chan.bindQueue('queue', 'exchange', 'route', {}, function (er) {
chan.consume('queue', onMessage, {}, function (er) {
cb(null, chan) // Ready!
})
function onMessage () { /* Eat some messages! */ }
})
})
})
}
```