来自 erlang shell 的 Rabbitmq 客户端抛出错误

Rabbitmq Client from erlang shell throwing error

我正在尝试使用 amqp_client 库连接到 rabbitmq。我按照 here.

提供的步骤操作

我的rabbitmq版本是RabbitMQ 3.5.7,Erlang 18.3。所以我从 https://www.rabbitmq.com/releases/rabbitmq-erlang-client/v3.5.7/ 下载了相应的文件。并解压缩到“/usr/lib/erlang/lib/”路径。然后在 erlang shell 我开始像下面这样

application:start(xmerl).
application:start(amqp_client).
application:start(rabbit_common).
rr("/usr/lib/erlang/lib/amqp_client-3.5.7/include/amqp_client.hrl").
#amqp_params_network{}.
{ok, Connection} = amqp_connection:start(#amqp_params_network{port=5672}).

在这一步我得到了一些崩溃报告

=ERROR REPORT==== 3-Feb-2017::18:55:10 ===
** Generic server <0.99.0> terminating 
** Last message in was connect
** When Server state == {<0.98.0>,
                         {amqp_params_network,<<"guest">>,<<"guest">>,
                             <<"/">>,"localhost",5672,0,0,10,infinity,none,
                             [#Fun<amqp_auth_mechanisms.plain.3>,
                              #Fun<amqp_auth_mechanisms.amqplain.3>],
                             [],[]}}
** Reason for termination == 
** {function_clause,
       [{amqp_gen_connection,terminate,
            [{undef,
                 [{rabbit_misc,ntoab,[{127,0,0,1}],[]},
                  {rabbit_net,connection_string,2,[]},
                  {amqp_network_connection,try_handshake,3,[]},
                  {amqp_gen_connection,handle_call,3,[]},
                  {gen_server,try_handle_call,4,
                      [{file,"gen_server.erl"},{line,629}]},
                  {gen_server,handle_msg,5,
                      [{file,"gen_server.erl"},{line,661}]},
                  {proc_lib,init_p_do_apply,3,
                      [{file,"proc_lib.erl"},{line,240}]}]},
             {<0.98.0>,
              {amqp_params_network,<<"guest">>,<<"guest">>,<<"/">>,
                  "localhost",5672,0,0,10,infinity,none,
                  [#Fun<amqp_auth_mechanisms.plain.3>,
                   #Fun<amqp_auth_mechanisms.amqplain.3>],
                  [],[]}}],
            []},
        {gen_server,try_terminate,3,[{file,"gen_server.erl"},{line,643}]},
        {gen_server,terminate,7,[{file,"gen_server.erl"},{line,809}]},
        {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,240}]}]}
** exception exit: {{function_clause,
                        [{amqp_gen_connection,terminate,
                             [{undef,
                                  [{rabbit_misc,ntoab,[{127,0,0,1}],[]},
                                   {rabbit_net,connection_string,2,[]},
                                   {amqp_network_connection,try_handshake,3,[]},
                                   {amqp_gen_connection,handle_call,3,[]},
                                   {gen_server,try_handle_call,4,
                                       [{file,"gen_server.erl"},{line,629}]},
                                   {gen_server,handle_msg,5,
                                       [{file,"gen_server.erl"},{line,661}]},
                                   {proc_lib,init_p_do_apply,3,
                                       [{file,"proc_lib.erl"},{line,240}]}]},
                              {<0.98.0>,
                               #amqp_params_network{
                                   username = <<"guest">>,password = <<"guest">>,
                                   virtual_host = <<"/">>,host = "localhost",port = 5672,
                                   channel_max = 0,frame_max = 0,heartbeat = 10,
                                   connection_timeout = infinity,ssl_options = none,
                                   auth_mechanisms = 
                                       [#Fun<amqp_auth_mechanisms.plain.3>,
                                        #Fun<amqp_auth_mechanisms.amqplain.3>],
                                   client_properties = [],socket_options = []}}],
                             []},
                         {gen_server,try_terminate,3,
                             [{file,"gen_server.erl"},{line,643}]},
                         {gen_server,terminate,7,
                             [{file,"gen_server.erl"},{line,809}]},
                         {proc_lib,init_p_do_apply,3,
                             [{file,"proc_lib.erl"},{line,240}]}]},
                    {gen_server,call,[<0.99.0>,connect,infinity]}}
     in function  gen_server:call/3 (gen_server.erl, line 212)

我不明白为什么会出现此错误?

[{undef,[{rabbit_misc表示找不到函数

您应该尝试使用 erl -pa /your_path_beam 执行程序,并将所有 .beam 文件放在那里。

另一种方法是使用 rebar3 where you can easily create and app and the add amqp_client dependency ( from https://hex.pm/).

非常类似于java maven