RabbitMQ 连接错误“没有指定的端点可访问”

问题描述 投票:0回答:13

我在服务器和我的系统上安装了rabbitmq服务。 我想使用 RPC 模式:

var factory = new ConnectionFactory() { 
  HostName = "158.2.14.42", 
  Port = Protocols.DefaultProtocol.DefaultPort, 
  UserName = "Administrator", 
  Password = "@server@", 
  VirtualHost = "/"
  ContinuationTimeout = new TimeSpan(10, 0, 0, 0) 
};

connection = factory.CreateConnection();

我在创建与此消息的连接时出错:
指定的端点均无法到达

当我在服务器的本地主机实例上使用它时,它可以工作,但是当我创建从本地到该服务器的连接时,它返回了错误。 它不适用于我的本地计算机的本地 IP 以及用户名和密码。


有人可以帮助我吗?

c# asp.net rabbitmq
13个回答
25
投票

正如这个问题提到的。
安装 RabbitMQ 后,我在服务器和本地计算机上启用了管理工具:

rabbitmq-plugins enable rabbitmq_management

然后我从

services.msc
重新启动了RabbitMQ服务
我可以在
http://localhost:15672
看到 Rabbitmq 管理
我使用用户:guest 和通行证:guest 登录兔子管理
我添加了我最喜欢的具有管理员访问权限的用户通行证,所以它起作用了。


10
投票

我也面临同样的问题,后来意识到我必须打开两个端口,即 15672 和 5672。

以下命令在 docker 容器模型中适用于我。

docker run -it --rm --name mymq -p 5672:5672 -p 15672:15672 rabbitmq:3-management

代码片段:

 var factory = new RabbitMQ.Client.ConnectionFactory
            {
                Uri = new Uri("amqp://guest:guest@localhost:5672/")
            };

var factory = new ConnectionFactory() { HostName = "localhost" };

4
投票

请勿使用访客。创建自己的帐户和密码,并在 http://localhost:15672/#/users 中确保“可以访问虚拟主机”为“/”

var factory = new ConnectionFactory() { 
  HostName = "192.168.1.121",
  Port = 5672,
  UserName = "fancky", 
  Password = "123456" 
};

3
投票

在我们的例子中,这是

System.Threading.Tasks.Extensions
的程序集绑定失败,我们的异常记录器没有记录
InnerException

Exception information: 
    Exception type: FileLoadException 
    Exception message: Could not load file or assembly 'System.Threading.Channels, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection..ctor(ConnectionFactory factory, String clientProvidedName)
   at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName) in /_/projects/RabbitMQ.Client/client/api/ConnectionFactory.cs:line 494

非常糟糕的误导性错误消息。


1
投票

这意味着客户端无法访问服务器

158.2.14.42
和默认虚拟主机
/

也许是防火墙配置


1
投票

默认情况下,正如您所说,RabbitMQ 将侦听

5672
但这可以更改,如果您查看配置(在 MQ 服务器上),您应该找到一个部分:

rabbit.tcp_listeners

其中将详细说明正在使用的端口。看看是不是你想的那样。

另外,您使用的是 IPv4 还是 IPv6?您可能需要额外的配置来支持两者。

阅读本文:

https://www.rabbitmq.com/networking.html


1
投票

1) 打开 RabbitMQ 命令提示符

2) 将路径更改为“C:\Program Files\RabbitMQ Server abbitmq_server-3.6.10\sbin”安装了rabbitmq_server。

3)运行以下命令: rabbitmq-plugins启用rabbitmq_management

如果防火墙屏蔽了,则弹出显示。为此允许防火墙。

现在您可以在浏览器中访问了。


1
投票

误导性错误。本地版本可以正常工作,但远程服务器却不能。结果我没有提供远程服务器必需的凭据,即用户名和密码。本地服务器无需它们即可轻松连接。


0
投票

我一直遇到这个问题,最后只是将 URI 提供为小写,而机器名称为大写。

因为花了几个小时才弄清楚,我认为这可能对其他人有帮助。


0
投票

我使用.netcore和rabbitmq创建了一个小应用程序,并使用下面的docker-compose代码在docker中为它们创建了图像-

version: '3'
services:
rabbitmq:
container_name: rabbitmq
hostname: "rabbitmq"
image: rabbitmq:3-management
ports:
- "5672:5672"
- "15672:15672"
volumes:
- rabbitmq:/rabbitmq
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:15672"]
interval: 30s
timeout: 10s
retries: 5

isp_hub:
depends_on:
- rabbitmq
build:
context: .
dockerfile: Dockerfile
ports:
- "9090:80"

volumes:
rabbitmq:

after running the cmd docker-compose up the image is created and container is started and i am using Jmeter client to hit the container .net code is working but while trying to pass the data in queue getting below exception -

"log":"info: Microsoft.Hosting.Lifetime[0]\r\n","stream":"stdout","time":"2022-04-04T08:25:22.6109672Z"}
{"log":" Application is shutting down...\r\n","stream":"stdout","time":"2022-04-04T08:25:22.6109672Z"}
{"log":"info: Microsoft.Hosting.Lifetime[0]\r\n","stream":"stdout","time":"2022-04-04T08:25:38.4488984Z"}
{"log":" Now listening on: http://[::]:80\r\n","stream":"stdout","time":"2022-04-04T08:25:38.4488984Z"}
{"log":"info: Microsoft.Hosting.Lifetime[0]\r\n","stream":"stdout","time":"2022-04-04T08:25:38.4498991Z"}
{"log":" Application started. Press Ctrl+C to shut down.\r\n","stream":"stdout","time":"2022-04-04T08:25:38.4498991Z"}
{"log":"info: Microsoft.Hosting.Lifetime[0]\r\n","stream":"stdout","time":"2022-04-04T08:25:38.4498991Z"}
{"log":" Hosting environment: Production\r\n","stream":"stdout","time":"2022-04-04T08:25:38.4498991Z"}
{"log":"info: Microsoft.Hosting.Lifetime[0]\r\n","stream":"stdout","time":"2022-04-04T08:25:38.4498991Z"}
{"log":" Content root path: C:\app\r\n","stream":"stdout","time":"2022-04-04T08:25:38.4498991Z"}
{"log":"fail: Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher[8]\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" Failed to invoke hub method 'SendToMessageBroker'.\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" ---\u003e System.AggregateException: One or more errors occurred. (Connection failed)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" ---\u003e RabbitMQ.Client.Exceptions.ConnectFailureException: Connection failed\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" ---\u003e System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at System.Threading.Tasks.ValueTask.ValueTaskSourceAsTask.\u003c\u003ec.\u003c.cctor\u003eb__4_0(Object state)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" --- End of stack trace from previous location ---\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.Impl.TcpClientAdapter.ConnectAsync(String host, Int32 port)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.Impl.TaskExtensions.TimeoutAfter(Task task, TimeSpan timeout)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, TimeSpan timeout)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" --- End of inner exception stack trace ---\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient socket, AmqpTcpEndpoint endpoint, TimeSpan timeout)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingAddressFamily(AmqpTcpEndpoint endpoint, Func2 socketFactory, TimeSpan timeout, AddressFamily family)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"} {"log":" at RabbitMQ.Client.Impl.SocketFrameHandler.ConnectUsingIPv4(AmqpTcpEndpoint endpoint, Func2 socketFactory, TimeSpan timeout)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.Impl.SocketFrameHandler..ctor(AmqpTcpEndpoint endpoint, Func2 socketFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"} {"log":" at RabbitMQ.Client.Framing.Impl.IProtocolExtensions.CreateFrameHandler(IProtocol protocol, AmqpTcpEndpoint endpoint, Func2 socketFactory, TimeSpan connectionTimeout, TimeSpan readTimeout, TimeSpan writeTimeout)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.ConnectionFactory.CreateFrameHandler(AmqpTcpEndpoint endpoint)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func2 selector)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"} {"log":" --- End of inner exception stack trace ---\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"} {"log":" at RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver resolver, Func2 selector)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(IEndpointResolver endpoints)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" --- End of inner exception stack trace ---\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.ConnectionFactory.CreateConnection(String clientProvidedName)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at RabbitMQ.Client.ConnectionFactory.CreateConnection()\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at ISP_Hub.HubConfig.CenterHub.SendToMessageBroker(String requestData) in C:\src\ISP_Hub\HubConfig\CenterHub.cs:line 38\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at Microsoft.Extensions.Internal.ObjectMethodExecutor.\u003c\u003ec__DisplayClass33_0.\u003cWrapVoidMethod\u003eb__0(Object target, Object[] parameters)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}
{"log":" at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher1.ExecuteMethod(ObjectMethodExecutor methodExecutor, Hub hub, Object[] arguments)\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"} {"log":" at Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher1.\u003c\u003ec__DisplayClass16_0.\u003c\u003cInvoke\u003eg__ExecuteInvocation|0\u003ed.MoveNext()\r\n","stream":"stdout","time":"2022-04-04T08:26:55.7889752Z"}

rabbitmq connection code -

public void SendToMessageBroker(string requestData)
{
var trace = JsonConvert.DeserializeObject(requestData);
// string rabbitMqUrl = "127.0.0.1";
// var factory = new ConnectionFactory() { HostName = "172.24.17.225", Port = 5672 };
//var factory = new ConnectionFactory
//{
// HostName = rabbitMqUrl,
// UserName = "guest",
// Password = "guest",
// Port = AmqpTcpEndpoint.UseDefaultPort,
// VirtualHost = "/",
// RequestedHeartbeat = new TimeSpan(60),
// Ssl = { ServerName = rabbitMqUrl, Enabled = false }
//};
var factory = new RabbitMQ.Client.ConnectionFactory
{
Uri = new Uri("amqp://guest:guest@localhost:5672/")
};
using var conn = factory.CreateConnection();
using var channel = conn.CreateModel();
RabbitMQPublisher.Publish(channel, trace);
Clients.All.SendAsync("test");
channel.Close();
conn.Close();
Debug.WriteLine("Show Message: " + requestData);

    }
i am new to docker . please help me to understand the issue and how to resolve it

0
投票

不知道它是否对您有帮助,但在将 .net 4.6.1 的 RabbitMQ.Client 从 5.1.2 更新到 5.2.0 后会发生这种情况。 如果您将目标框架提高到 4.8,它就会通过。


0
投票

我的问题是我创建了一个

guest
用户,密码为
guest
,显然这不起作用。一旦我选择了不同的用户名和密码,它就对我有用。


0
投票

如果项目是dockerized的:

应该使用host.docker.internal(或适当的URL...)而不是localhost。

© www.soinside.com 2019 - 2024. All rights reserved.