[rabbitmq-discuss] Message receive error

Alexander Kuleshov kuleshovmail at gmail.com
Wed Jul 6 08:50:46 BST 2011


Hello,

I have code

-module(send).
-export([main/0]).

-include_lib("amqp_client/include/amqp_client.hrl").

main() ->
    io:format("Connect \n"),
    {ok, Connection} =
        amqp_connection:start(#amqp_params_network{host = "localhost",
						   password = <<"password">>}),

    io:format("Open channel \n"),
    {ok, Channel} = amqp_connection:open_channel(Connection),
    amqp_channel:call(Channel, #'queue.declare'{queue = <<"test1">>}),
    amqp_channel:subscribe(Channel, #'basic.consume'{queue =
<<"test2">>}, self()),

   io:format("send message \n"),

    Message = <<"test message">>,
    amqp_channel:cast(Channel, #'basic.publish'{exchange = <<"">>,
routing_key = <<"test1">>},
		      #amqp_msg{payload = Message}),

    io:format("message sended \n"),

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

loop(Channel) ->
    io:format("Loop start"),
    receive
	{#'basic.deliver'{delivery_tag = Tag}, Content} ->
	    io:format("Message receive"),
	    amqp_channel:cast(Channel, #'basic.ack'{delivery_tag = Tag}),
	    loop(Channel);
	_ ->
	    loop(Channel)
    end.


I get error when run it:

Eshell V5.8.1  (abort with ^G)
1> send:main().
Connect
Open channel
** exception exit: {{shutdown,{server_initiated_close,404,
                                                      <<"NOT_FOUND -
no queue 'test2' in vhost '/'">>}},
                    {gen_server,call,
                                [<0.48.0>,

{subscribe,{'basic.consume',0,<<"test2">>,<<>>,false,

false,false,false,[]},
                                            <0.32.0>},
                                 infinity]}}
     in function  gen_server:call/3
     in call from send:main/0

How can i send and receive message?

Thank you.


More information about the rabbitmq-discuss mailing list