[rabbitmq-discuss] Erlang Consumer Example

Matthias Radestock matthias at rabbitmq.com
Mon Jul 30 10:52:07 BST 2012


On 29/07/12 21:59, anton prokofiev wrote:
> On Sunday, 29 July 2012 21:21:06 UTC+2, anton prokofiev wrote:
>     I tried to create  a consumer in Erlang for RabbitMQ and get into
>     big troubles.
>     Looks like examples that are available in RabbitMQ website did not work.

*Which* example didn't work?

> Looks like I have found a correct solution:
> 1. I have implemented simple gen_server, that just print all messages to
> the stdout.
> 2. And  to like this:
>    {ok,Connection} = amqp_connection:start(ConnectionParams), % open
> connection with predefined params.
>    {ok,Pid} =  test_srv:start_link(),    % Start our own consumer.
> {ok,Channel}  =
> amqp_connection:open_channel(Connection,none,*{amqp_direct_consumer,[Pid]}*),

The above creates a channel with a default consumer. More typically 
you'd associate consumers with particular subscriptions, as shown in 

> Would it be better to create my own implementation of consume behavior,
> or handle them thought the message_info as it is now?
> Any recommendations?

Implementing your own instance of the amqp_gen_consumer behaviour is 
probably the more "correct" approach, but it's a bit more work and if 
the behaviour of the amqp_direct_consumer fits in well with the rest of 
your system design then just use that.



More information about the rabbitmq-discuss mailing list