1.0.1 • Published 11 months ago

queue-sdk-rabbitmq v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

QUEUE LISTENER

CREATE QUEUE LISTENER 1. Create file in the associated directory (directory name doesn't matter). 2. 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: 1. Create send.js file with following code:

export default async message => {
    console.log(message);
};
  1. Pass path to handlers in init method of Queue class.
const queueListener = Queue.init({CONNECTION_STRING, 'QUENAME_TO_LISTEN', 'PATH_TO_HANDLERS'});
  1. Send message to RabbitMQ queue with action "send" and you will get in your handler.
1.0.1

11 months ago

1.0.0

11 months ago