使用#amqp_params_direct{}的Erlang Direct(Erlang分发版)客户端?

6yoyoihd  于 2023-01-22  发布在  Erlang
关注(0)|答案(1)|浏览(115)

这里我可以直接连接兔子节点:

(app@centos7-mq)1> net_kernel:connect_node('rabbit@centos7-mq').
true
(app@centos7-mq)2> nodes().
['rabbit@centos7-mq']

但使用程序时显示错误。

Erlang RabbitMQ Client library

RabbitParams=#amqp_params_direct{username=?RABBIT_USERNAME,
                      password=?RABBIT_PASSWORD, virtual_host=?VHOST, node='rabbit@centos7-mq'},
    Connection = amqp_connection:start(RabbitParams),
    io:format("amqp_connection:start result: ~p~n", [Connection]).

错误内容如下:

amqp_connection:start result: {error,{nodedown,'rabbit@centos7-mq'}}

那么,它有什么问题吗?
=============这是示例

-module(amqp_direct).
-include_lib("amqp_client/include/amqp_client.hrl").
-compile([export_all]).
-compile(nowarn_export_all).
-define(RABBIT_USERNAME, <<"your user">>).
-define(RABBIT_PASSWORD, <<"your password">>).
-define(VHOST, <<"your vhost">>).
-define(NODE, 'your server node').

connect_amqp() ->
    RabbitParams=#amqp_params_direct{username=?RABBIT_USERNAME,
                      password=?RABBIT_PASSWORD, virtual_host=?VHOST, node=?NODE},
    io:format("amqp_connection:start begin ~n"),
    Connection = amqp_connection:start(RabbitParams),
    io:format("amqp_connection:start result: ~p~n", [Connection]),
    Connection.

start() ->
   Connection=amqp_example:connect_amqp(),
   "Finish".
pengsaosao

pengsaosao1#

我尝试使用选项--sname test,然后它的作品.

rebar3 shell --sname test
===> Verifying dependencies...
.....

(test@centos7-mq)1> amqp_direct:start().
amqp_connection:start begin
=WARNING REPORT==== 21-Jan-2023::00:37:40.121828 ===
AMQP 0-9-1 client call timeout was 70000 ms, is updated to a safe effective value of 130000 ms
amqp_connection:start result: {ok,<0.310.0>}
"Finish"

我读了源代码文件amqp_client/src/amqp_connection.erl,它使我有这样的尝试。

connect(Params = #amqp_params_direct{username     = Username,
                                     password     = Password,
                                     node         = Node,
                                     adapter_info = Info,
                                     virtual_host = VHost},
        SIF, _TypeSup, State) ->
....
    case rpc:call(Node, rabbit_direct, connect,
                  [{Username, DecryptedPassword}, VHost, ?PROTOCOL, self(),
                   connection_info(State1)], ?DIRECT_OPERATION_TIMEOUT) of

相关问题