我试图尝试使用RabbitMQ Erlang客户端绑定。我想从Erlang shell中做到这一点。
我可以成功加载相关模块,我可以加载记录类型:
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中使用这些东西?
答案 0 :(得分:1)
shell和记录并不总是很好。试试这个:
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 = []}