Tags

,

A useful library for connecting to RabbitMQ via Erlang is gen_bunny. There are a lot of good things about it, but it is really designed for simple pub/sub applications in a modified gen_server paradigm. I had a need for connecting a gen_fsm instance to RabbitMQ. So rather than using gen_bunny for certain modules and a bespoke library for the others, I decided to write a simple wrapper library that can integrate into any Erlang module. I couldn’t resist the bunny meme, so welcome to the bunny_farm.

The point of bunny_farm is to make the wiring easy in custom applications. Note that the messages will still arrive via handle_info in a gen_server or gen_fsm.

Consuming Messages from a Topic Exchange

BusHandle = bunny_farm:open(ExchangeName, RoutingKey)
bunny_farm:consume(BusHandle)

Publishing Messages to a Topic Exchange

BusHandle = bunny_farm:open(ExchangeName)
bunny_farm:publish(Message, RoutingKey, BusHandle)

Support for RPC messages

BusHandle = bunny_farm:open(ExchangeName, RoutingKey)
bunny_farm:rpc({Procedure,Arguments}, ReplyTo, BusHandle)

The library is still in its infancy but should still be useful in simplifying integration of existing Erlang modules with RabbitMQ.