Rabbitmq Client from erlang shell throwing error - erlang

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?

[{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

Related

How do I disable the error logger in EUnit test cases?

When running an EUnit test that tests an application or starts and stops (or tests killing of) gen_server or supervisor processs, error logger outputs crash reports and other messages by default:
$ rebar3 eunit 1s
===> Verifying dependencies...
===> Compiling my_app
===> Performing EUnit tests...
...........=INFO REPORT==== 5-Sep-2019::16:32:18.760457 ===
application: ranch
exited: stopped
type: temporary
=INFO REPORT==== 5-Sep-2019::16:32:18.760545 ===
application: xmerl
exited: stopped
type: temporary
=INFO REPORT==== 5-Sep-2019::16:32:18.763882 ===
application: my_app
exited: stopped
type: temporary
......=ERROR REPORT==== 5-Sep-2019::16:32:18.814431 ===
** Generic server my_app_sup terminating
** Last message in was {'EXIT',<0.279.0>,test_kill}
** When Server state == {state,
{local,my_app_sup},
simple_one_for_one,
{[undefined],
#{undefined =>
{child,undefined,undefined,
{my_app_server,start_link,[]},
transient,5000,worker,
[my_app_server]}}},
{maps,#{<0.355.0> => [my_app_test]}},
1,5,[],0,my_app_sup,[]}
** Reason for termination ==
** test_kill
=CRASH REPORT==== 5-Sep-2019::16:32:18.814598 ===
crasher:
initial call: supervisor:my_app_sup/1
pid: <0.354.0>
registered_name: my_app_sup
exception exit: test_kill
in function gen_server:decode_msg/9 (gen_server.erl, line 432)
ancestors: [<0.279.0>]
message_queue_len: 0
messages: []
links: []
dictionary: []
trap_exit: true
status: running
heap_size: 1598
stack_size: 27
reductions: 6463
neighbours:
...........
Finished in 0.457 seconds
28 tests, 0 failures
How can I avoid these expected messages during testing?
These can be avoided by temporarily disabling TTY reports in the error logger. Surround the code which produces the reports with this:
my_test() ->
error_logger:tty(false),
try
% code that produces error logger reports
after
error_logger:tty(true)
end.
If you use this many times in the tests, this wrapper can be useful:
without_error_logger(Fun) ->
error_logger:tty(false),
try
Fun()
after
error_logger:tty(true)
end.
Which is used like so:
without_error_logger(fun() ->
% code that produces error logger reports
end)

RabbitMQ/Erlang crashing: Cannot reallocate 313760 bytes of memory (of type "code")

Can anyone please help to understand these crash logs?
RabbitMQ 3.6.6, Erlang 19.1
RabbitMQ is running on Microsoft Windows Web Server 2008 R2 6.1.7601 Service Pack 1 Build 7601 64bit.
RabbitMQ started to crash yesterday after running OK about one year. Now I have upgraded Erlang and RabbitMQ Server to the versions mentioned above but this did not change anything - still crashing
frequently.
.log:
=ERROR REPORT==== 13-Dec-2016::22:13:55 ===
** Generic server rabbit_disk_monitor terminating
** Last message in was update
** When Server state == {state,"d:/ETOIMI~1/RabbitMQ/RABBIT~1",50000000,
14439952384,100,10000,#Ref<0.0.1.27257>,false,
true}
** Reason for termination ==
** {eacces,[{erlang,open_port,
[{spawn,"C:\\Windows\\system32\\cmd.exe /c dir /-C /W \"d:/ETOIMI~1/RabbitMQ/RABBIT~1\""},
[binary,stderr_to_stdout,stream,in,hide]],
[{file,"erlang.erl"},{line,2080}]},
{os,cmd,1,[{file,"os.erl"},{line,230}]},
{rabbit_disk_monitor,get_disk_free,2,
[{file,"src/rabbit_disk_monitor.erl"},
{line,218}]},
{rabbit_disk_monitor,internal_update,1,
[{file,"src/rabbit_disk_monitor.erl"},
{line,193}]},
{rabbit_disk_monitor,handle_info,2,
[{file,"src/rabbit_disk_monitor.erl"},
{line,165}]},
{gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,601}]},
{gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,667}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]}
-sasl.log:
=CRASH REPORT==== 13-Dec-2016::22:13:55 ===
crasher:
initial call: rabbit_disk_monitor:init/1
pid: <0.211.0>
registered_name: rabbit_disk_monitor
exception exit: {eacces,
[{erlang,open_port,
[{spawn,
"C:\\Windows\\system32\\cmd.exe /c dir /-C /W \"d:/ETOIMI~1/RabbitMQ/RABBIT~1\""},
[binary,stderr_to_stdout,stream,in,hide]],
[{file,"erlang.erl"},{line,2080}]},
{os,cmd,1,[{file,"os.erl"},{line,230}]},
{rabbit_disk_monitor,get_disk_free,2,
[{file,"src/rabbit_disk_monitor.erl"},
{line,218}]},
{rabbit_disk_monitor,internal_update,1,
[{file,"src/rabbit_disk_monitor.erl"},
{line,193}]},
{rabbit_disk_monitor,handle_info,2,
[{file,"src/rabbit_disk_monitor.erl"},
{line,165}]},
{gen_server,try_dispatch,4,
[{file,"gen_server.erl"},{line,601}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,667}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,247}]}]}
in function gen_server:terminate/7 (gen_server.erl, line 812)
ancestors: [rabbit_disk_monitor_sup,rabbit_sup,<0.164.0>]
messages: []
links: [<0.210.0>]
dictionary: []
trap_exit: false
status: running
heap_size: 6772
stack_size: 27
reductions: 381464
neighbours:
=SUPERVISOR REPORT==== 13-Dec-2016::22:13:55 ===
Supervisor: {local,rabbit_disk_monitor_sup}
Context: child_terminated
Reason: {eacces,
[{erlang,open_port,
[{spawn,
"C:\\Windows\\system32\\cmd.exe /c dir /-C /W \"d:/ETOIMI~1/RabbitMQ/RABBIT~1\""},
[binary,stderr_to_stdout,stream,in,hide]],
[{file,"erlang.erl"},{line,2080}]},
{os,cmd,1,[{file,"os.erl"},{line,230}]},
{rabbit_disk_monitor,get_disk_free,2,
[{file,"src/rabbit_disk_monitor.erl"},{line,218}]},
{rabbit_disk_monitor,internal_update,1,
[{file,"src/rabbit_disk_monitor.erl"},{line,193}]},
{rabbit_disk_monitor,handle_info,2,
[{file,"src/rabbit_disk_monitor.erl"},{line,165}]},
{gen_server,try_dispatch,4,
[{file,"gen_server.erl"},{line,601}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,667}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,247}]}]}
Offender: [{pid,<0.211.0>},
{name,rabbit_disk_monitor},
{mfargs,{rabbit_disk_monitor,start_link,[50000000]}},
{restart_type,{transient,1}},
{shutdown,30000},
{child_type,worker}]
Also I have found Erlang crash dump, please see
HERE
If there is more information that should be provided by me please let me know.
Thank you!
** {eacces,[{erlang,open_port,
[{spawn,"C:\\Windows\\system32\\cmd.exe /c dir /-C /W \"d:/ETOIMI~1/RabbitMQ/RABBIT~1\""},
eacces is an Erlang error:
eacces Missing search or write permissions for the parent directories
of Dir.
most likely the service has problems to access here: d:/ETOIMI~1/RabbitMQ/RABBIT~1\

Connecting to RabbitMQ server from MongooseIM

I am trying to communicate with a rabbitmq server from my mongooseim server. For that first I copied rabbitmq-client library (for erlang) to my apps directory, updated my makefile and then recompiled mongooseim code. (as per the instruction from here). This way I can compile the code with no error and can see amqp_client has been started from mongooseim console. Now when I try to run amqp_connection:start() from the console I get the below error. How to fix this?
(mongooseim#localhost)8> {ok, Connection} = amqp_connection:start(#amqp_params_network{}).
2015-04-23 15:07:27.320 [debug] <0.790.0> Supervisor {<0.790.0>,amqp_connection_sup} started amqp_connection_type_sup:start_link() at pid <0.791.0>
2015-04-23 15:07:27.324 [debug] <0.790.0> Supervisor {<0.790.0>,amqp_connection_sup} started amqp_gen_connection:start_link(<0.791.0>, {amqp_params_network,<<"guest">>,<<"guest">>,<<"/">>,"localhost",5672,0,0,0,infinity,none,[#Fun<amq..>,...],...}) at pid <0.792.0>
** exception exit: {{function_clause,[{amqp_gen_connection,terminate,
[{undef,[{rabbit_net,connection_string,
[#Port<0.6063>,outbound],
[]},
{amqp_network_connection,try_handshake,3,[]},
{amqp_gen_connection,handle_call,3,[]},
{gen_server,try_handle_call,4,
[{file,"gen_server.erl"},{line,607}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,639}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]},
{<0.791.0>,
#amqp_params_network{username = <<"guest">>,
password = <<"guest">>,virtual_host = <<"/">>,
host = "localhost",port = 5672,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 = []}}],
[]},
{gen_server,try_terminate,3,
[{file,"gen_server.erl"},{line,621}]},
{gen_server,terminate,7,
[{file,"gen_server.erl"},{line,787}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,237}]}]},
{gen_server,call,[<0.792.0>,connect,infinity]}}
in function gen_server:call/3 (gen_server.erl, line 190)
(mongooseim#localhost)9> 2015-04-23 15:07:27.411 [error] <0.792.0> gen_server <0.792.0> terminated with reason: no function clause matching amqp_gen_connection:terminate({undef,[{rabbit_net,connection_string,[#Port<0.6063>,outbound],[]},{amqp_network_connection,try_handshake,...},...]}, {<0.791.0>,{amqp_params_network,<<"guest">>,<<"guest">>,<<"/">>,"localhost",5672,0,0,0,infinity,...}})
2015-04-23 15:07:27.412 [error] <0.792.0> CRASH REPORT Process <0.792.0> with 0 neighbours exited with reason: no function clause matching amqp_gen_connection:terminate({undef,[{rabbit_net,connection_string,[#Port<0.6063>,outbound],[]},{amqp_network_connection,try_handshake,...},...]}, {<0.791.0>,{amqp_params_network,<<"guest">>,<<"guest">>,<<"/">>,"localhost",5672,0,0,0,infinity,...}}) in gen_server:terminate/7 line 792
2015-04-23 15:07:27.414 [error] <0.790.0> Supervisor {<0.790.0>,amqp_connection_sup} had child connection started with amqp_gen_connection:start_link(<0.791.0>, {amqp_params_network,<<"guest">>,<<"guest">>,<<"/">>,"localhost",5672,0,0,0,infinity,none,[#Fun<amq..>,...],...}) at <0.792.0> exit with reason no function clause matching amqp_gen_connection:terminate({undef,[{rabbit_net,connection_string,[#Port<0.6063>,outbound],[]},{amqp_network_connection,try_handshake,...},...]}, {<0.791.0>,{amqp_params_network,<<"guest">>,<<"guest">>,<<"/">>,"localhost",5672,0,0,0,infinity,...}}) in context child_terminated
2015-04-23 15:07:27.416 [error] <0.790.0> Supervisor {<0.790.0>,amqp_connection_sup} had child connection started with amqp_gen_connection:start_link(<0.791.0>, {amqp_params_network,<<"guest">>,<<"guest">>,<<"/">>,"localhost",5672,0,0,0,infinity,none,[#Fun<amq..>,...],...}) at <0.792.0> exit with reason reached_max_restart_intensity in context shutdown
The undef error message tells us that the rabbit_net module or the connection_string function is missing and rabbit_net is a part of rabbit_common package. I guess you didn't add rabbit_common. You can find the package on the website you pasted in the previous question - here. Repeat the steps with rabbit_common.ez and it should work.

Erlang sellaprime OTP application

I'm trying to run the sellaprime example OTP application from Chapter 23 of Programming Erlang 2nd Ed. I have uploaded the code to https://github.com/myles-mcdonnell/sellaprime
After compiling with rebar I run erl from the root, then switch dir ..
1> c(src).
/Users/mylesmcdonnell/sellaprime/src
ok
then I load the app..
2> application:load(sellaprime).
ok
then I try to start the app..
3> application:start(sellaprime).
=CRASH REPORT==== 5-Feb-2015::09:55:34 ===
crasher:
initial call: application_master:init/4
pid: <0.48.0>
registered_name: []
exception exit: {bad_return,
{{sellaprime_app,start,[normal,[]]},
{'EXIT',
{undef,
[{sellaprime_app,start,[normal,[]],[]},
{application_master,start_supervisor,3,
[{file,"application_master.erl"},
{line,326}]},
{application_master,start_the_app,5,
[{file,"application_master.erl"},
{line,308}]},
{application_master,start_it_new,7,
[{file,"application_master.erl"},
{line,294}]}]}}}}
in function application_master:init/4 (application_master.erl, line 133)
ancestors: [<0.47.0>]
messages: [{'EXIT',<0.49.0>,normal}]
links: [<0.47.0>,<0.7.0>]
dictionary: []
trap_exit: true
status: running
heap_size: 610
stack_size: 27
reductions: 124
neighbours:
=INFO REPORT==== 5-Feb-2015::09:55:34 ===
application: sellaprime
exited: {bad_return,
{{sellaprime_app,start,[normal,[]]},
{'EXIT',
{undef,
[{sellaprime_app,start,[normal,[]],[]},
{application_master,start_supervisor,3,
[{file,"application_master.erl"},{line,326}]},
{application_master,start_the_app,5,
[{file,"application_master.erl"},{line,308}]},
{application_master,start_it_new,7,
[{file,"application_master.erl"},
{line,294}]}]}}}}
type: temporary
{error,
{bad_return,
{{sellaprime_app,start,[normal,[]]},
{'EXIT',
{undef,
[{sellaprime_app,start,[normal,[]],[]},
{application_master,start_supervisor,3,
[{file,"application_master.erl"},{line,326}]},
{application_master,start_the_app,5,
[{file,"application_master.erl"},{line,308}]},
{application_master,start_it_new,7,
[{file,"application_master.erl"},{line,294}]}]}}}}}
Clearly something is undefined but I'm struggling to determine what? I have lifted the code directly from the book download site with no changes.

riak-erlang-client fails to ping riak node

My riak node is not responding to ping yet everything seems ok
(myclient#127.0.0.1)2> {ok, Pid} = riakc_pb_socket:start_link("127.0.0.1", 10018).
{ok,<0.217.0>}
(myclient#127.0.0.1)3> riakc_pb_socket:ping(Pid).
** exception exit: disconnected
(myclient#127.0.0.1)4>
=ERROR REPORT==== 21-Dec-2014::04:41:22 ===
** Generic server <0.217.0> terminating
** Last message in was {req_timeout,#Ref<0.0.0.306>}
** When Server state == {state,"127.0.0.1",10018,false,false,undefined,
undefined,
{[],[]},
1,[],infinity,100}
** Reason for termination ==
** disconnected
What is that i am not doing right??
Thanks in advance.
Port 10018 is the HTTP listening port for a Riak cluster set up in development mode, but you're using the protocol buffers client. Try port 10017 instead.

Resources