Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
amqp-message-bus
Advanced tools
Node.js message bus interface for AMQP servers, such as RabbitMQ.
$ npm install amqp-message-bus
Install amqp-message-bus
from npm.
$ npm install amqp-message-bus --save
Create new message bus.
const MessageBus = require('amqp-message-bus');
const bus = new MessageBus({
queue: 'tasks',
url: 'amqp://localhost',
encryptionKey: 'keep-it-safe'
});
Connect to AMQP server and subscribe for messages.
bus.connect()
.then(() => bus.subscribe((msg, props, done) => {
// process msg + props
console.log(`Received message ${props.messageId} with priority ${props.priority}, published on ${props.timestamp}`);
// call done when message is done processing to remove from rabbitmq
done();
}))
// call this when you want to unsubscribe...
.then((unsubscribe) => unsubscribe())
// always catch errors with promises :-)
.catch((err) => console.error(err));
The same looks much better using async/await.
await bus.connect();
const unsubscribe = await bus.subscribe((msg, props, done) => {
// process msg + props
console.log(`Received message ${props.messageId} with priority ${props.priority}, published on ${props.timestamp}`);
// call done when ready to remove message from rabbitmq
done();
});
// call this when you want to unsubscribe...
await unsubscribe();
Connect to AMQP server, publish message and immediately disconnect.
bus.connect()
.then(() => bus.publish({ foo: 1, bar: 2 }))
.catch((err) => console.error(err))
.finally(() => bus.disconnect);
Constructs new message bus with the supplied properties.
spec
(Object) message bus properties (required).
spec.url
(string) AMQP server URL (required).spec.queue
(string) the name of the queue to subscribe to (required).spec.encryptionKey
(string) encryption key to use with assymetric encryption (optional). Signifies no encryption if left unspecified.const bus = new MessageBus({
queue: 'tasks',
url: 'amqp://localhost',
encryptionKey: 'keep-it-safe'
});
Connects to AMQP server using the connection properties specified at construction time.
Returns a native Promise.
bus.connect()
.then(() => {
console.log('Connected to amqp server');
})
.catch((err) => {
console.error(err);
});
Disconnects from AMQP server.
Returns a native Promise.
bus.disconnect()
.then(() => {
console.log('Disconnected from amqp server');
})
.catch((err) => {
console.error(err);
});
Subscribes to the message bus for incoming messages.
listener
(Function<Object, Object, Function>) listener function (required).msg
(Object) message body (required).props
(Object) message meta-data (required).done
(Function) call done to signal message proccessing is done (required).Please visit http://www.squaremobius.net/amqp.node/channel_api.html#channel_assertQueue for further info on props
meta-data.
Returns a native Promise resolving to an unsubscribe()
method.
const listener = (msg, props, done) => {
// do something with msg and props
console.log(JSON.stringify(msg, null, 2));
// call done when you are done with msg to remove from queue
done();
};
bus.subscribe(listener)
.then((unsubscribe) => {
// unsubscribe when ready
unsubscribe();
})
.catch((err) => {
console.error(err);
});
const unsubscribe = await bus.subscribe((msg, props, done) => {
// do something with msg and props
console.log(JSON.stringify(msg, null, 2));
// call done when you are done with msg to remove from queue
done();
});
// unsubscribe when ready
await unsubscribe();
Publishes the supplied message to the AMQP server.
content
(*) message body (required); can be any JSON serializable value, e.g. Object, Array.props
(Object) message props (optional).
props.id
(string) message ID (optional; defaults to UUID v4
)props.priority
(integer) message priority, must be between 1 and 10 (optional; defaults to 1)props.timestamp
(number) message timestamp (optional; defaults to Date.now()
)props.type
(string) message type (optional)Returns a native Promise resolving to a boolean value.
bus.publish({ foo: 'bar' }, { type: 'nonsense', priority: 10 })
.catch((err) => {
console.error(err);
});
await bus.publish({ foo: 'bar' }, { type: 'nonsense', priority: 10 });
Source code contributions are most welcome. The following rules apply:
FAQs
Node.js message bus interface for AMQP servers, such as RabbitMQ.
We found that amqp-message-bus 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
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.