2014-01-20 67 views
2

我正在嘗試使用RabbitMQ Erlang客戶端綁定。我想從Erlang shell執行此操作。從Erlang shell使用rabbitmq-erlang-client?

我可以成功加載相關的模塊,我可以加載記錄類型:

1> rr(amqp_connection). 
['P_access','P_basic','P_channel'|...] 
2> rl(amqp_params_network). 
-record(amqp_params_network,{username = <<"guest">>, 
          password = <<"guest">>, 
          virtual_host = <<"/">>, 

...等。

但是當我嘗試真正連接:

{ok, C} = amqp_connection:start(#amqp_params_network{}). 

...我得到的錯誤...

** exception error: no function clause matching 
    erl_eval:expr(amqp_auth_mechanisms,[], 
    {eval,#Fun<shell.21.103280319>}, 
    {value,#Fun<shell.5.103280319>}, 
    none) (erl_eval.erl, line 200) 

我能想到的唯一的事情就是amqp_params_network有一些功能默認記錄值:

... 
ssl_options = none, 
auth_mechanisms = 
[fun amqp_auth_mechanisms:plain/3, 
fun amqp_auth_mechanisms:amqplain/3], 
client_properties = [], 
... 

我怎麼能通過這個,以便我可以玩這個東西在Erlang shell?

回答

1

外殼和記錄不總是混合良好。試試這個:

1> rr(amqp_connection). 
['P_access','P_basic','P_channel','P_confirm', 
'P_connection','P_dtx','P_exchange','P_file','P_queue', 
'P_stream','P_test','P_tunnel','P_tx','access.request', 
'access.request_ok',amqp_adapter_info,amqp_error,amqp_msg, 
amqp_params_direct,amqp_params_network,amqqueue,'basic.ack', 
'basic.cancel','basic.cancel_ok','basic.consume', 
'basic.consume_ok','basic.deliver','basic.get', 
'basic.get_empty'|...] 
2> P=#amqp_params_network{auth_mechanisms=[fun amqp_auth_mechanisms:plain/3, fun amqp_auth_mechanisms:amqplain/3]}. 
#amqp_params_network{username = <<"guest">>, 
        password = <<"guest">>,virtual_host = <<"/">>, 
        host = "localhost",port = undefined,channel_max = 0, 
        frame_max = 0,heartbeat = 0,connection_timeout = infinity, 
        ssl_options = none, 
        auth_mechanisms = [#Fun<amqp_auth_mechanisms.plain.3>, 
             #Fun<amqp_auth_mechanisms.amqplain.3>], 
        client_properties = [],socket_options = []} 
3> amqp_connection:start(P). 
{ok,<0.42.0>} 
4> 

或者:

1> rd(params, {username   = <<"guest">>, 
1>        password   = <<"guest">>, 
1>        virtual_host  = <<"/">>, 
1>        host    = "localhost", 
1>        port    = undefined, 
1>        channel_max  = 0, 
1>        frame_max   = 0, 
1>        heartbeat   = 0, 
1>        connection_timeout = infinity, 
1>        ssl_options  = none, 
1>        auth_mechanisms = 
1>         [fun amqp_auth_mechanisms:plain/3, 
1>         fun amqp_auth_mechanisms:amqplain/3], 
1>        client_properties = [], 
1>        socket_options  = []}). 
params 
2> P=#params{}. 
#params{username = <<"guest">>,password = <<"guest">>, 
     virtual_host = <<"/">>,host = "localhost",port = undefined, 
     channel_max = 0,frame_max = 0,heartbeat = 0, 
     connection_timeout = infinity,ssl_options = none, 
     auth_mechanisms = [#Fun<amqp_auth_mechanisms.plain.3>, 
          #Fun<amqp_auth_mechanisms.amqplain.3>], 
     client_properties = [],socket_options = []} 
+0

我與第一變型成功。 –