Consumer as the background process
๐งพ Consumer as a Background Process
In your messaging configuration, you have the ability to run certain channels in background consumer mode, meaning the application will continuously poll and process messages from a queue (e.g., RabbitMQ).
This behavior is explicitly controlled using the enableConsumer
flag inside the channel configuration.
โ
Enabling or Disabling Consumers
Each channel can individually opt into message consumption:
Setting enableConsumer: true
allows the messaging module to automatically listen to that queue and handle incoming messages to the proper handlers in your NestJS app.
If you set:
This makes it super easy to spin up separate workers or scale differently for message producers and consumers.
Great addition! Here's how you can present this as part of your Consumer as a Background Process page, demonstrating how to run the consumer logic separately using NestJS microservices:
โ๏ธ Running the Consumer as a Dedicated Microservice
In addition to toggling enableConsumer
in your channel config, you can fully isolate message consumption into its own process using NestJS microservice mode.
This is useful when you want to separate HTTP requests from background processing, scale them independently, or run consumers in isolated environments (e.g., workers).
๐ From HTTP App to Microservice Consumer
Your standard main.ts
for a typical HTTP NestJS app might look like this:
You can create worker.ts
a microservice-based consumer by doing the following:
โ
Microservice Consumer Entry
๐ง Tip: Using
Transport.TCP
here simply satisfies the NestJS microservice API; actual messaging will still be handled by RabbitMQ, SQS, Redis, etc. You can safely ignore it or replace it withTransport.NONE
if you donโt need internal messaging.
Last updated