2.0.5 • Published 6 years ago

@coolgk/amqp v2.0.5

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

@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';
// OR
// const { Amqp } = require('@coolgk/amqp');

const amqp = new Amqp({
    url: 'amqp://localhost/vhost'
});

const message = {
    a: 1,
    b: 'b'
};

// CONSUMER MUST BE STARTED FIRST BEFORE PUSHLISHING ANY MESSAGE

// consumer.js
// consume message and return (send) a response back to publisher
amqp.consume(({rawMessage, message}) => {
    console.log('consumer received', message); // consumer received ignore response
                                               // consumer received { a: 1, b: 'b' }
    return {
        response: 'response message'
    }
});

// publisher.js
// publish a message, no response from consumer
amqp.publish('ignore response');

// publish a message and handle response from consumer
amqp.publish(message, ({rawResponseMessage, responseMessage}) => {
    console.log('response from consumer', responseMessage); // response from consumer { response: 'response message' }
});


// example to add:
// consume from (multiple) routes
// round robin consumers
// direct route + a catch all consumer

Amqp

Kind: global class

new Amqp(options)

ParamTypeDescription
optionsobject
options.urlstringconnection string e.g. amqp://localhost
options.sslPemstringpem file path
options.sslCastringsslCa file path
options.sslPassstringpassword

amqp.closeConnection() ⇒ void

Kind: instance method of Amqp

amqp.publish(message, callback, options) ⇒ promise.<Array.<boolean>>

Kind: instance method of Amqp

ParamTypeDefaultDescription
message*message any type that can be JSON.stringify'ed
callbackfunctioncallback(message) for processing response from consumers
optionsobject
options.routesstring | Array.<string>"'#'"route names
options.exchangeNamestring"'defaultExchange'"exchange name

amqp.consume(callback, options) ⇒ promise

Kind: instance method of Amqp

ParamTypeDefaultDescription
callbackfunctionconsumer(message) function should returns a promise
optionsobject
options.routesstring | Array.<string>"'#'"exchange routes
options.queueNamestring"''"queue name for processing messages. consumers with the same queue name process messages in round robin style
options.exchangeNamestring"'defaultExchange'"exchange name
options.exchangeTypestring"'topic'"exchange type
options.prioritynumber0priority, larger numbers indicate higher priority
options.prefetchnumber11 or 0, if to process request one at a time

amqp.getChannel() ⇒ promise

Kind: instance method of Amqp
Returns: promise - - promise

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago