[rabbitmq-discuss] pub-sub erlang problem

Joe Lee codewalkerjoe at gmail.com
Sun Apr 6 22:53:04 BST 2008


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20080406/e41c0ee2/attachment.htm 


More information about the rabbitmq-discuss mailing list