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. <br>
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?<br>
<br>I am new to erlang. This shouldn't be a show stopper. I just need to get this working. I am getting following error:<br><br>(rabbit@home)1> amqp_async:amqp_lifecycle().<br>
Connection: {<0.217.0>,direct}<br>
<br>
=ERROR REPORT==== 6-Apr-2008::16:33:51 ===<br>
Lax ticket check mode: ignoring cross-realm access for ticket 101<br>
** exception exit: {{amqp,not_found,'basic.publish'},<br>
{gen_server,call,<br>
[<0.218.0>,<br>
{call,{'channel.close',200,<<"Goodbye">>,0,0}}]}}<br>
in function gen_server:call/2<br>
in call from amqp_async:amqp_lifecycle/0<br><br>my pub-sub code:<br><br>-module(amqp_async).<br><br>-include_lib("rabbitmq_server/include/rabbit_framing.hrl").<br>-include_lib("rabbitmq_server/include/rabbit.hrl").<br>
<br>-export([amqp_lifecycle/0]).<br><br>amqp_lifecycle() -><br> User = Password = "guest",<br> Realm = <<"/data">>,<br><br> %% Start a connection to the server<br><br> Connection = amqp_connection:start(User, Password),<br>
io:format("Connection: ~p~n",[Connection]),<br> %% Once you have a connection to the server, you can start an AMQP channel gain access to a realm<br><br> Channel = amqp_connection:open_channel(Connection),<br>
Access = #'access.request'{realm = Realm,<br> exclusive = false,<br> passive = true,<br> active = true,<br> write = true,<br>
read = true},<br> #'access.request_ok'{ticket = Ticket} = amqp_channel:call(Channel, Access),<br> <br> X = <<"x">>,<br> RoutingKey = <<"a.b.c.*">>,<br>
Payload = <<"foobar">>,<br> BasicPublish = #'basic.publish'{ticket = Ticket,<br> exchange = X,<br> routing_key = RoutingKey,<br>
mandatory = false,<br> immediate = false},<br> Content = #content{class_id = 60,<br> properties = amqp_util:basic_properties(),<br> properties_bin = none,<br>
payload_fragments_rev = [Payload]<br> },<br> amqp_channel:cast(Channel, BasicPublish, Content),<br> <br> %% After you've finished with the channel and connection you should close them down<br>
<br> ChannelClose = #'channel.close'{reply_code = 200, reply_text = <<"Goodbye">>,<br> class_id = 0, method_id = 0},<br> #'channel.close_ok'{} = amqp_channel:call(Channel, ChannelClose),<br>
ConnectionClose = #'connection.close'{reply_code = 200, reply_text = <<"Goodbye">>,<br> class_id = 0, method_id = 0},<br> #'connection.close_ok'{} = amqp_connection:close(Connection, ConnectionClose),<br>
ok.<br><br>Thank you,<br>Joe<br><br><br><br><br>