0
votes

I am trying connect to rabbitmq using amqp_client library. I followed the steps provided here.

My rabbitmq version is RabbitMQ 3.5.7, Erlang 18.3. So I downloaded respective files from https://www.rabbitmq.com/releases/rabbitmq-erlang-client/v3.5.7/. and unzipped to "/usr/lib/erlang/lib/" path. then in erlang shell i started like below

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}).

In this step I got Some crash report

=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)

I am not getting why I am getting this error?

1

1 Answers

1
votes

[{undef,[{rabbit_misc means that it can't find the function.

you should try to execute the program using erl -pa /your_path_beam and put there all the .beam files.

Another way is to use rebar3 where you can easily create and app and the add amqp_client dependency ( from https://hex.pm/).

It is very similar to java maven