Recently I was struggling to understand how a customers RabbitMq project was wired up so I created an example .NET app to play around with it. Turns out their setup code didn’t create bindings and routes out of the box - no wonder it didn’t work when I ran the acceptance tests!
The demo app has two console apps, one publishing messages to the RabbitMq exchange and one subscribed to a RabbitMq queue. We create a RabbitMq exchange and subscribe the queue to all messages sent to the exchange.
Installing RabbitMq on the local machine
RabbitMq is pretty easy to get started with on Windows but with everything is harder at scale. RabbitMq runs atop Erlang, which has a simple Windows installer. After installing Erlang, the RabbitMq service needs to be installed using the RabbitMq installer and then the service must be started and running.
To gain visibility of messages entering RabbitMq and routes they take, you can enable the HTTP management utility which is a web-based administration interface that will run on your local machine.
Enabling the HTTP management utility
You’ll need an exchange to send messages to (a postbox). You’ll then need to route the messages to clients (routed to sub-exchanges and queues).
Getting the RabbitMq .NET client
I used the RabbitMq NuGet Client package for this.
Authenticating RabbitMq using the .NET client
Creating a RabbitMq exchange and routing messages to a RabbitMq queue using the .NET Client
Actions here are idempotent, meaning you can run this more than once and get the same result out of it. If the exchange or queue already exists, you shouldn’t run into any problems.
Send a message to the RabbitMq exchange using the .NET Client
Subscribing to a RabbitMq queue and handling messages using the .NET Client
Check out my Github RabbitMq Example to get the source