queue-sdk-rabbitmq
v1.0.1
Published
SDK for queue sdk
Downloads
188
Readme
QUEUE LISTENER
CREATE QUEUE LISTENER
- Create file in the associated directory (directory name doesn't matter).
- Setup class instance with following fields:
connectionString: String [required] - Connection url to RabbitMQ.
queueName: String [required] - Queue name to listen.
handlersPath: String [optional] - Path to handlers that will handle specific actions in message from RabbitMQ.
reconnectDuration: Int [optional] - Recconect duration.
EXAMPLE OF INSTANCE SETUP:
import Queue from '@asrp/queue-sdk'
const {
RABBITMQ_DEFAULT_USER,
RABBITMQ_DEFAULT_PASS
} = process.env;
const queueConfig = {
user: RABBITMQ_DEFAULT_USER,
password: RABBITMQ_DEFAULT_PASS,
queueName: 'QUENAME_TO_LISTEN'
}
const queue = Queue.init(queueConfig);
EXAMPLE OF HANDLER:
- Create send.js file with following code:
export default async message => {
console.log(message);
};
- Pass path to handlers in init method of Queue class.
const queueListener = Queue.init({CONNECTION_STRING, 'QUENAME_TO_LISTEN', 'PATH_TO_HANDLERS'});
- Send message to RabbitMQ queue with action "send" and you will get in your handler.