RabbitMQ
The RabbitMQ is the most widely deployed open source message broker.
Installation
Before we start, we have to install required packages:
$ npm i --save amqplib amqp-connection-manager
Transporter
In order to switch to RabbitMQ transporter, we need to modify an options object passed to the createMicroservice()
method.
@@filename(main)
const app = await NestFactory.createMicroservice(ApplicationModule, {
transport: Transport.RMQ,
options: {
urls: [`amqp://localhost:5672`],
queue: 'cats_queue',
queueOptions: { durable: false },
},
});
info Hint
Transport
enumerator is imported from the@nestjs/microservices
package.
Options
There are a bunch of available options that determine a transporter behavior.
urls | Connection urls |
queue | Queue name which your server will listen to |
prefetchCount | Sets the prefetch count for the channel |
isGlobalPrefetchCount | Enables per channel prefetching |
queueOptions | Additional queue options. They are well-described here |
socketOptions | Additional socket options. They are well-described here |