Mavnn's blog

Stuff from my brain

Representing EasyNetQ Message Subscriptions as Blocking Queues

EasyNetQ ( is a simple wrapper for RabbitMq that allows you to trivially send and receive plain .net objects over the wire (as long as they can be serialized). It handles all the details of setting up exchanges and queues for you, and as long as your use case fits its (deliberately) simple pattern it’s very convenient.

Unfortunately, if you want to use it in a more functional landscape (*cough* from F# *cough*), the fact that it exposes subscriptions via registering a callback is not the ideal interface. In these situations, it’s much easier to handle (and reason about) a lazy infinite sequence of messages that you can then handle however you want, including in the simplest case just sitting on the sequence in a small tail call recursive function.
So EasyFQ was born. Weighing in at a mighty 16 lines of F# code, it contains one function: SeqSubscibe<’a> : (IBus -> string -> seq<’a>).
There’s a .fsx with example usage in the GitHub repository:
I suppose the next step is to pester Mike into making it a Nuget package under the EasyNetQ umbrella…