[rabbitmq-discuss] pub-sub erlang problem
Ben Hood
0x6e6562 at gmail.com
Tue Apr 8 13:00:56 BST 2008
Joe,
Sorry about the delay in answering your question.
It looks like you're trying to publish to an exchange that doesn't
exist, although the server diagnostic could be a little clearer on
this point.
To fix your test, precede the exchange declare command before the
publish command, i.e. put this code before the publish call:
ExchangeDeclare = #'exchange.declare'{ticket = Ticket, exchange = X,
type = <<"topic">>,
passive = false, durable =
false, auto_delete = false, internal = false,
nowait = false, arguments =
[]},
#'exchange.declare_ok'{} = amqp_channel:call(Channel, ExchangeDeclare)
We should probably take on board better server diagnostics as an
improvement item.
HTH,
Ben
On 6 Apr 2008, at 22:53, Joe Lee wrote:
> I am trying to get pub-sub model to work in rabbitmq. My
> understanding is that you still have to perform
> amqp_connection:start, amqp_connection:open_channel,
> amqp_channel:call(Channel, Access), channel close and connection
> close on each async call.
> I am not sure what payload_fragments_rev = [Payload] is for. I have
> searched through amqp xml specs and pdf. Maybe I am not hitting the
> right keywords. For pub-sub model, how do you assign the message,
> assign it to Payload variable?
>
> I am new to erlang. This shouldn't be a show stopper. I just need
> to get this working. I am getting following error:
>
> (rabbit at home)1> amqp_async:amqp_lifecycle().
> Connection: {<0.217.0>,direct}
>
> =ERROR REPORT==== 6-Apr-2008::16:33:51 ===
> Lax ticket check mode: ignoring cross-realm access for ticket 101
> ** exception exit: {{amqp,not_found,'basic.publish'},
> {gen_server,call,
> [<0.218.0>,
> {call,{'channel.close',200,<<"Goodbye">>,
> 0,0}}]}}
> in function gen_server:call/2
> in call from amqp_async:amqp_lifecycle/0
>
> my pub-sub code:
>
> -module(amqp_async).
>
> -include_lib("rabbitmq_server/include/rabbit_framing.hrl").
> -include_lib("rabbitmq_server/include/rabbit.hrl").
>
> -export([amqp_lifecycle/0]).
>
> amqp_lifecycle() ->
> User = Password = "guest",
> Realm = <<"/data">>,
>
> %% Start a connection to the server
>
> Connection = amqp_connection:start(User, Password),
> io:format("Connection: ~p~n",[Connection]),
> %% Once you have a connection to the server, you can start an
> AMQP channel gain access to a realm
>
> Channel = amqp_connection:open_channel(Connection),
> Access = #'access.request'{realm = Realm,
> exclusive = false,
> passive = true,
> active = true,
> write = true,
> read = true},
> #'access.request_ok'{ticket = Ticket} =
> amqp_channel:call(Channel, Access),
>
> X = <<"x">>,
> RoutingKey = <<"a.b.c.*">>,
> Payload = <<"foobar">>,
> BasicPublish = #'basic.publish'{ticket = Ticket,
> exchange = X,
> routing_key = RoutingKey,
> mandatory = false,
> immediate = false},
> Content = #content{class_id = 60,
> properties = amqp_util:basic_properties(),
> properties_bin = none,
> payload_fragments_rev = [Payload]
> },
> amqp_channel:cast(Channel, BasicPublish, Content),
>
> %% After you've finished with the channel and connection you
> should close them down
>
> ChannelClose = #'channel.close'{reply_code = 200, reply_text =
> <<"Goodbye">>,
> class_id = 0, method_id = 0},
> #'channel.close_ok'{} = amqp_channel:call(Channel, ChannelClose),
> ConnectionClose = #'connection.close'{reply_code = 200,
> reply_text = <<"Goodbye">>,
> class_id = 0, method_id =
> 0},
> #'connection.close_ok'{} = amqp_connection:close(Connection,
> ConnectionClose),
> ok.
>
> Thank you,
> Joe
>
>
>
>
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
More information about the rabbitmq-discuss
mailing list