2
votes

I'm trying to experiment with the RabbitMQ Erlang client bindings. I want to do this from the Erlang shell.

I can successfully load the relevant modules, and I can load the record types:

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 = <<"/">>,

...etc.

but when I try to actually connect:

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

...I get the error...

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

The only thing I can think of is that amqp_params_network has some functions as default record values:

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

How do I get past this, so that I can play with this stuff in the Erlang shell?

1

1 Answers

1
votes

The shell and records don't always mix well. Try this:

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>

Or:

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 = []}