[rabbitmq-discuss] consuming problems

Matthias Radestock matthias at lshift.net
Fri Jun 5 07:43:41 BST 2009


Jack,

Jack Moffitt wrote:
> So I've been able to figure out how to create queues, exchanges and
> bindings, and also to publish messages to an exchange.  I can't find
> documentation for what class_id does in the #content record, but
> apparently it's required.  I set it to 60 which was what the only
> example I could find used.

The class_id refers to the AMQP content class, of which there is only 
one defined in the current spec. It's called 'basic' and the id of it is 
indeed 60.

> Now I'm trying to consume things from the queue.
> 
> BasicConsume  = #'basic.consume'{queue = <<"tostorage">>, consumer_tag
> = <<"">>}.
> #'basic.consume_ok'{consumer_tag = <<"">>} =
> amqp_channel:call(Channel, BasicConsume, self()).
> 
> fails with:
> 
> Channel 1 is shutting down due to: {{badmatch,false},
>                                     [{rabbit_writer,assemble_frames,4},
>                                      {rabbit_writer,
>                                       internal_send_command_async,5},
>                                      {rabbit_writer,handle_message,2},
>                                      {rabbit_writer,mainloop,1}]}
> 
> which seems to be from this line of rabbit_writer:assemble_frames/4:
> 
> true = rabbit_framing:method_has_content(MethodName), % assertion
> 
> And now I'm completely stuck again.

amqp_channel:call/3 is defined as follows:

%% Generic AMQP send mechanism with content
call(Channel, Method, Content) ->
     gen_server:call(Channel, {call, Method, Content}).

So, as you can see, this function is for sending content-bearing 
methods. 'basic.consume' is not content-bearing, and setting the content 
to self() won't work, for obvious reasons.

You'll probably want to use amqp_channel:subscribe/3 instead.


Also, have you looked at lib_amqp.erl? It contains a number of 
convenient wrappers around the core API.


Regards,

Matthias




More information about the rabbitmq-discuss mailing list