@coolgk/amqp
a javascript / typescript module
npm install @coolgk/amqp
a simple RabbitMQ (amqp wrapper) class for publishing and consuming messages
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.<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.route] | string | "'#'" | route name |
[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.route] | string | "'#'" | exchange route |
[options.queueName] | string | "''" | queue name for processing request |
[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 | 0 | 1 or 0, if to process request one at a time |