这里我可以直接连接兔子节点:
(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".
1条答案
按热度按时间pengsaosao1#
我尝试使用选项
--sname test
,然后它的作品.我读了源代码文件
amqp_client/src/amqp_connection.erl
,它使我有这样的尝试。