SR Queue Consumer Pattern - Part 2
Connecting SRQC to a Message Queue Service
This post extends the queue consumer pattern discussed here to utilize a message brokering service. The implementation described here is using RabbitMQ.
Two queues will be used, one for inbound message handling and one for outbound message handling. These queues will be operating as Message Channels to facilitate asynchronous communication between the components. One channel is reponsible for the message producer to message processor inbound path and the other is responsible for the message processor outbound path to the message consumer.
The following diagram illustrates the described system.

Operation
The system consists of the following components
| Component | Description |
|---|---|
| Message Producer | Console application that produces a configurable number of messages and Publishes them to the Inbound Queue |
| Inbound Queue | A typical inbound queue in a Message Orientated Middleware (MOM) style application. A RabbitMQ Queue in this system. |
| Message Processor | An IHostedServive that receives Messages from the Inbound Queue, handles the SRQC libraries as described here for processing and publishes the results to the Outbound Queue. |
| Outbound Queue | A typical outbound queue in a Message Orientated Middleware (MOM) style application. A RabbitMQ Queue in this system. |
| Message Consumer | Console application responsible for Receiving and Handling Messages placed in the Outbound Queue |
RabbitMQ Implementation Notes
For this implementation the use of RabbitMQ relies mostly on the defaults. There is however one component that deserves some attention, and that is the use of the Consumer Prefetch count.
The consumer prefetch count in RabbitMQ controls the maximum number of unacknowledged messages a consumer can receive from RabbitMQ at any given time. In this demonstration is set at the channel level with a call to the BasicQosAsync() function.
await channel.BasicQosAsync(0, _channelReader.PrefetchCount, false);
Since we are using an async, event driven, consumer the prefetch count is used to limit the ‘inflight’ messages a consumer needs to handle. This limits resources required and reduces messages that are ‘at risk’ during the handling process.
Running the Project
Detailed instructions for running the project can be found here.