This is an simplified and padronized RabbitMQ Client for NodeJS
Create a connection
import{Connection}from'@eduzz/rabbit';exportconstmyRabbit=newConnection({dsn: 'amqp://...',exchange: 'my-exchange'});Send an message to an topic:
import{myRabbit}from'./myRabbit';constpayload={hello: 'world'};myRabbit.topic('some.topic').persistent().send({ payload });Listen to one or multiple topics:
import{myRabbit}from'./myRabbit';myRabbit.queue('my.queue').topic('some.topic').topic('another.topic').durable().retryTimeout(60000).listen(asyncdata=>{console.log(data);returntrue;});import{Connection}from'@eduzz/rabbit';constconnection=newConnection({dsn: 'amqp://....',exchange: 'theExchange',exchangeType: 'topic',connectionName: 'my app'});// Listening some topicawaitconnection.queue('my.queue').topic('my.topic').durable().retryTimeout(60000).listen<string>(asyncmsg=>{console.log(msg);returntrue;});// Publishing message(async()=>{constpublisher=connection.topic('my.topic').persistent();setInterval(async()=>{constpayload={number: Math.random()*1000};publisher.send({
payload
});},1000);})();// Delaying Messagesconnection.delayQueue('my.delay.queue').durable().from('from.topic').to('to.topic').timeout(5000).create();