未处理的异常。 RabbitMQ.Client.Exceptions.BrokerUnreachableException:指定的端点均不可到达

Posted

技术标签:

【中文标题】未处理的异常。 RabbitMQ.Client.Exceptions.BrokerUnreachableException:指定的端点均不可到达【英文标题】:Unhandled exception. RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable 【发布时间】:2020-11-25 04:14:13 【问题描述】:

我已经使用这个 docker 镜像在我的笔记本电脑上设置了 RabbitMQ 服务器。

https://hub.docker.com/_/rabbitmq

和命令:docker run -d --hostname rabbit-release --name rabbit-releaset -p 15672:15672 -p 5672:5672 rabbitmq:3-management

和设置:

"rabbitMq": 
    "namespace": "common",
    "retries": 3,
    "retryInterval": 2,
    "username": "guest",
    "password": "guest",
    "virtualHost": "/",
    "port": 5672,
    "hostnames": [
      "rabbit-release"
    ],
    "requestTimeout": "00:00:10",
    "publishConfirmTimeout": "00:00:01",
    "recoveryInterval": "00:00:10",
    "persistentDeliveryMode": true,
    "autoCloseConnection": true,
    "automaticRecovery": true,
    "topologyRecovery": true,
    "exchange": 
      "durable": true,
      "autoDelete": false,
      "type": "Topic"
    ,
    "queue": 
      "autoDelete": false,
      "durable": true,
      "exclusive": false
    
  ,

这是已退出容器的日志:

未处理的异常。 RabbitMQ.Client.Exceptions.BrokerUnreachableException:没有 指定的端点是可达的---> RabbitMQ.Client.Exceptions.ConnectFailureException:连接失败 ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (111): 连接被拒绝 127.0.0.1:5672 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(异常 源)在 System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) 在 System.Net.Sockets.Socket.c.b__275_0(IAsyncResult iar) --- 从之前抛出异常的位置结束堆栈跟踪 --- 在 RabbitMQ.Client.TcpClientAdapter.ConnectAsync(String 主机,Int32 端口)在 RabbitMQ.Client.Impl.TaskExtensions.TimeoutAfter(任务任务,Int32 毫秒超时)在 RabbitMQ.Client.Impl.SocketFrameHandler.ConnectOrFail(ITcpClient 套接字,AmqpTcpEndpoint 端点,Int32 超时)--- 内部结束 异常堆栈跟踪 --- 在 RabbitMQ.Client.EndpointResolverExtensions.SelectOne[T](IEndpointResolver 解析器,Func2 selector) at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(IEndpointResolver endpoints) at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName) --- End of inner exception stack trace --- at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName) at RabbitMQ.Client.ConnectionFactory.CreateConnection(IList1 主机名, 字符串 clientProvidedName) 在 RabbitMQ.Client.ConnectionFactory.CreateConnection(IList1 hostnames) at RawRabbit.Channel.ChannelFactory.ConnectAsync(CancellationToken token) at RawRabbit.DependencyInjection.RawRabbitDependencyRegisterExtension.<>c.<AddRawRabbit>b__0_3(IDependencyResolver resolver) at RawRabbit.DependencyInjection.SimpleDependencyInjection.<>c__DisplayClass4_02.b__0() 在 System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy1.CreateValue() at System.Lazy1.get_Value() 在 RawRabbit.DependencyInjection.SimpleDependencyInjection.c__DisplayClass4_02.<AddSingleton>b__1(IDependencyResolver resolver) at RawRabbit.DependencyInjection.SimpleDependencyInjection.GetService(Type serviceType, Object[] additional) at RawRabbit.DependencyInjection.SimpleDependencyInjection.GetService[TService](Object[] additional) at RawRabbit.Instantiation.InstanceFactory.Create() at iNRES.Common.RabbitMq.Extensions.AddRabbitMq(IServiceCollection services, IConfiguration configuration) at iNRES.Service.Common.Startup.ConfigureServices(IServiceCollection services) in /app/src/iNRES.Service.Common/Startup.cs:line 116 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.<Invoke>g__Startup|0(IServiceCollection serviceCollection) at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder1.c__DisplayClass15_0.g__RunPipeline|0(IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(对象 例如,IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.c__DisplayClass8_0.b__0(IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder`1.c__DisplayClass14_0.g__ConfigureServicesWithContainerConfiguration|0(IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.WebHost.EnsureApplicationServices() 在 Microsoft.AspNetCore.Hosting.WebHost.Initialize() 在 Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() 在 iNRES.Service.WaterResource.Program.Main(String[] args) 在 /app/src/iNRES.Service.Common/Program.cs:第 18 行

【问题讨论】:

【参考方案1】:

如果您在主机中运行客户端代码,则--hostname docker 选项无效,因此您需要在客户端代码中使用localhost 而不是rabbit-release

【讨论】:

以上是关于未处理的异常。 RabbitMQ.Client.Exceptions.BrokerUnreachableException:指定的端点均不可到达的主要内容,如果未能解决你的问题,请参考以下文章

SQL 异常未处理 - System.Data.dll 中出现“System.Data.SqlClient.SqlException”类型的未处理异常

如何生成未处理的 MFC 异常?

Elasticsearch未分配分片异常处理

在 mvc 中处理请求时发生未处理的异常

捕获未处理的异常

如何在未处理的任务异常上崩溃?