![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
runnable-hermes
Advanced tools
RabbitMQ AMQPLIB EventEmitter style pub/sub interface abstraction
Simplified abstraction interface to amqp.node
Publish & subscribe to RabbitMQ queues with simplified publish & subscribe interface methods.
durabale
queues, not transient
. persistent
messages will be saved to disk and survivie broker restarts. Queue Durabilitypublish
or subscribe
methods from your application.)done
method to send ack message to RabbitMQ and remove tasks from queue/**
* Hermes attempts to connect to RabbitMQ upon instantiation,
* throws if connection fails.
* If using Events, Hermes will throw if binding or asserting failed
* during connections
*/
var hermes = require('runnable-hermes').hermesSingletonFactory({
name: 'service name',
hostname: 'localhost',
port: '5672',
username: 'guest',
password: 'guest',
heartbeat: 10, // default 0 (no timeout)
persistent: true, // default true (messages will survive a broker restart event)
prefetch: 10 // sets the consumer prefetch for the channel (default to not being applied)
queues: [ // queues to self-register with RabbitMQ on connect
'task-queue-1',
'task-queue-2'
],
publishedEvents: [ // publish to fanout exchange
'task-queue-3',
'task-queue-4'
],
subscribedEvents: [ // read from fanout exchanges
'task-queue-5',
'task-queue-6'
]
}).connect();
var jobCallback = function (data, done) { //data automatically decoded into object or string
// perform operation w/ data
done(); // remove job from RabbitMQ queue
};
/**
* Hermes will auto-queue subscribe & publish calls if
* connection to RabbitMQ has not yet been established
*
* Will throw if first argument is not a string representing
* a valid RabbitMQ queue as defined in `queues`,
* `publishedEvents`, or `subscribedEvents` options
* passed to the constructor
*
* @param {String} queue name
* @param {Function} queue consumer callback
*/
hermes.subscribe('valid-queue-name', jobCallback);
/**
* Insert job into queue w/ associated job data.
*
* @param {String} queue name
* @param {Object|String} task data (automatically encoded as Buffer for transmisison to RabbitMQ, will be automatically decoded in subscribe)
*/
hermes.publish('valid-queue-name', {foo: 'bar'});
/**
* Remove bounded functions from queue events (abstracts AMQP cancel & consumerTags)
*
* @param {String} queue name
* @param {Function} reference to queue consumer callback used as argument to `hermes.subscribe`
* @param {Function} callback, invoked when queue consumer callback is no longer consuming from queue
*/
hermes.unsubscribe('valid-queue-name', jobCallback, function (err) {
// invoked when worker removed from RabbitMQ
});
// also, you can optionally remove all workers in a queue by providing null instead of a reference to a single queue consumer callback
hermes.unsubscribe('valid-queue-name', null, function (err) {});
/**
* Disconnecting & reconnecting
*/
hermes.close(cb);
hermes.connect(cb);
/**
* Fetch an array of valid queues
* @returns Array<String>
*/
var queues = hermes.getQueues();
/**
* Hermes class extends events.EventEmitter and emits the following events:
* - 'publish'
* - 'subscribe'
* - 'unsubscribe'
* - 'error'
* - 'ready'
* Examples:
*/
hermes
.connect()
.on('ready', function () {
console.log('hermes connected to RabbitMQ & queues asserted');
});
hermes.on('publish', function (queueName, data) {
console.log('hermes publish action', queueName, data);
});
hermes.publish('valid-queue-name', {foo: 'bar'});
hermes.on('subscribe', function (queueName, handlerFn) {
// Event listener recieves queueName and reference to assigned handler function
console.log('hermes subscribe action', queueName, handlerFn);
});
hermes.subscribe('valid-queue-name', subscribeCallback);
hermes.unsubscribe('valid-queue-name', null, unsubscribeAllCallback);
hermes.on('unsubscribe', function (queueName, handlerFn) {
// Invoked once per task-handler callback that is unsubscribed
// Event listener recieves queueName and reference to assigned handler function
console.log('hermes unsubscribe action', queueName, handlerFn);
});
$ npm test
$ npm run test-cov # will auto open Google Chrome
MIT
FAQs
RabbitMQ AMQPLIB EventEmitter style pub/sub interface abstraction
The npm package runnable-hermes receives a total of 11 weekly downloads. As such, runnable-hermes popularity was classified as not popular.
We found that runnable-hermes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.