1.0.0 • Published 7 years ago
rmq-proxy v1.0.0
rmq-proxy
Send HTTP requests through a RabbitMQ exchange/queue to one or more HTTP servers as a proxy to enable controlled request consumption
Usage
// on the app that is receiving messages
const connection = createRabbitMQConnection();
const { receiver } = require('rmq-proxy');
const closeReceiver = receiver({ connection, domains: ['my.domain.com'] });
// on app that is sending messages to the receiver application
const connection = createRabbitMQConnection();
const { sender } = require('rmq-proxy');
const { adapter } = await sender({ connection });
const axios = require('axios');
const response = await axios.get({ url: 'https://my.domain.com/something', adapter });
// request used the RMQ exchange and queues instead of HTTPMethods
sender
Returns an object with two properties
adapterandshutdown.
appId= The identifier of the app, default: random uuidconnection= Instance of amqplib.connect, optionalconnectionOptions= Optional way to specify amqplib.connect optionsexchange= The name of the exchange that is used to route messages to the domain queues created by the receiver method, defaults to 'http.proxy'.exchangeOptions= The options used to assert the exchange into existence, see available options, defaults to{ durable: true }.queueOptions= The options used to assert thereplyToqueue into existence, see available options, defaults to{ autoDelete: true, exclusive: false, durable: false, arguments: { 'x-queue-mode': 'lazy' } }.replyTo= The name used to create a queue capable of receiving the response message after the receiver has processed the request, defaults to random uuid.simultaneous= The number of simultaneous messages to process from thereplyToqueue, defaults to2.
receiver
Returns a function that shutsdown the rmq connection
appId= The identifier of the app, default: random uuidconnection= Instance of amqplib.connect, optionalconnectionOptions= Optional way to specify amqplib.connect optionsexchange= The name of the exchange that is used to route messages to the domain queues created by the receiver method, defaults to 'http.proxy'.exchangeOptions= The options used to assert the exchange into existence, see available options, defaults to{ durable: true }.queueOptions= The options used to assert thereplyToqueue into existence, see available options, defaults to{ autoDelete: true, exclusive: false, durable: false, arguments: { 'x-queue-mode': 'lazy' } }.domains= An array of domains or an object with domains as keys and queue options as the field values, defaults to{}limit= An async function that can delay execution of newly received request messages allowing limiting of execution, defaults toasync () => {}
1.0.0
7 years ago