[rabbitmq-discuss] Message receiving

Alexander Kuleshov kuleshovmail at gmail.com
Wed Jun 29 18:05:12 BST 2011


Hello,

I try to receive message from rabbitmq server. At the start i connect to server:

main() ->
    {ok, Connection} =
        amqp_connection:start(#amqp_params_network{host = "myhost.com",
						   password = <<"pasword">>}),

    {ok, Channel} = amqp_connection:open_channel(Connection),
    % remember pid
    ok = gen_fsm:sync_send_all_state_event({global, "game1"},
{set_channel, self()}),
    amqp_channel:call(Channel, #'queue.declare'{queue = <<"test">>}),
    amqp_channel:subscribe(Channel, #'basic.consume'{queue =
<<"test">>}, self()),

    receive
        #'basic.consume_ok'{} ->
	    ok
    end,
    loop(Channel).

My loop function:

loop(Channel) ->
        receive
        {#'basic.deliver'{delivery_tag = Tag}, #amqp_msg{payload = Body}} ->
            amqp_channel:cast(Channel, #'basic.ack'{delivery_tag = Tag}),
            loop(Channel);
	{ok, Message} ->
	    amqp_channel:cast(Channel, #'basic.publish'{routing_key =
<<"test">>}, #amqp_msg{payload = Message}),
	    loop(Channel)
    end.

I send message in {ok, Message} tuple from another code:

Chanel ! {ok, Message}.

Chanel i get from (  ok = gen_fsm:sync_send_all_state_event({global,
"game1"}, {set_channel, self()}), ) in main function. Then
amqp_channel:cast send message Message, but the answer does not come.
First lopp/1 clause not execute.

How can i send message from another module and receive answer in
loop/1 correctly?

Thank you.


More information about the rabbitmq-discuss mailing list