@coolgk/amqp
a javascript / typescript module
npm install @coolgk/amqp
a simple RabbitMQ (amqp wrapper) class for publishing and consuming messages
Report bugs here: https://github.com/coolgk/node-utils/issues
Examples
import { Amqp } from '@coolgk/amqp';
const amqp = new Amqp({
url: 'amqp://localhost/vhost'
});
const message = {
a: 1,
b: 'b'
};
amqp.consume(({rawMessage, message}) => {
console.log('consumer received', message);
return {
response: 'response message'
}
});
amqp.publish('ignore response');
amqp.publish(message, ({rawResponseMessage, responseMessage}) => {
console.log('response from consumer', responseMessage);
});
Amqp
Kind: global class
new Amqp(options)
Param | Type | Description |
---|
options | object | |
options.url | string | connection string e.g. amqp://localhost |
[options.sslPem] | string | pem file path |
[options.sslCa] | string | sslCa file path |
[options.sslPass] | string | password |
amqp.closeConnection() ⇒ void
Kind: instance method of Amqp
amqp.publish(message, [callback], [options]) ⇒ promise.<Array.<boolean>>
Kind: instance method of Amqp
Param | Type | Default | Description |
---|
message | * | | message any type that can be JSON.stringify'ed |
[callback] | function | | callback(message) for processing response from consumers |
[options] | object | | |
[options.routes] | string | Array.<string> | "['#']" | route names |
[options.exchangeName] | string | "'defaultExchange'" | exchange name |
amqp.consume(callback, [options]) ⇒ promise
Kind: instance method of Amqp
Param | Type | Default | Description |
---|
callback | function | | consumer(message) function should returns a promise |
[options] | object | | |
[options.routes] | string | Array.<string> | "['#']" | exchange routes |
[options.queueName] | string | "''" | queue name for processing messages. consumers with the same queue name process messages in round robin style |
[options.exchangeName] | string | "'defaultExchange'" | exchange name |
[options.exchangeType] | string | "'topic'" | exchange type |
[options.priority] | number | 0 | priority, larger numbers indicate higher priority |
[options.prefetch] | number | 1 | 1 or 0, if to process request one at a time |
amqp.getChannel() ⇒ promise
Kind: instance method of Amqp
Returns: promise
- - promise