DNC-DShop
DNC-DShop copied to clipboard
RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'
Hi, the code is best,
when i want run in debug mode i have an error with this title
Can you help me?
[20:17:25 INF] User profile is available. Using 'C:\Users\Hossein\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. [20:17:35 INF] Unable to connect to broker Application startup exception: Autofac.Core.DependencyResolutionException: An exception was thrown while activating ?:RawRabbit.IBusClient. ---> RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.IO.IOException: connection.start was never received, likely due to a network timeout at RabbitMQ.Client.Framing.Impl.Connection.StartAndTune() at RabbitMQ.Client.Framing.Impl.Connection.Open(Boolean insist) at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(IFrameHandler fh) 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 RawRabbit.Channel.ChannelFactory.ConnectAsync(CancellationToken token) at RawRabbit.DependencyInjection.RawRabbitDependencyRegisterExtension.<>c.<AddRawRabbit>b__0_3(IDependencyResolver resolver) at RawRabbit.DependencyInjection.SimpleDependencyInjection.<>c__DisplayClass4_02.<AddSingleton>b__0()
at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
at System.Lazy1.CreateValue() at RawRabbit.DependencyInjection.SimpleDependencyInjection.GetService(Type serviceType, Object[] additional) at RawRabbit.DependencyInjection.SimpleDependencyInjection.GetService[TService](Object[] additional) at RawRabbit.Instantiation.InstanceFactory.Create() at DShop.Common.RabbitMq.Extensions.<>c.<ConfigureBus>b__2_1(IComponentContext context) in C:\Users\Hossein\Desktop\Repository\Microservice\DNC\DNC-DShop.Common\src\DShop.Common\RabbitMq\Extensions.cs:line 89 at Autofac.Builder.RegistrationBuilder.<>c__DisplayClass0_01.<ForDelegate>b__0(IComponentContext c, IEnumerable1 p) in C:\projects\autofac\src\Autofac\Builder\RegistrationBuilder.cs:line 62 at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters) in C:\projects\autofac\src\Autofac\Core\Activators\Delegate\DelegateActivator.cs:line 71
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable1 parameters, Object& decoratorTarget) in C:\projects\autofac\src\Autofac\Core\Resolving\InstanceLookup.cs:line 118 --- End of inner exception stack trace --- at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable1 parameters, Object& decoratorTarget) in C:\projects\autofac\src\Autofac\Core\Resolving\InstanceLookup.cs:line 136
at Autofac.Core.Resolving.InstanceLookup.Execute() in C:\projects\autofac\src\Autofac\Core\Resolving\InstanceLookup.cs:line 85
at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable1 parameters) in C:\projects\autofac\src\Autofac\Core\Resolving\ResolveOperation.cs:line 130 at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable1 parameters) in C:\projects\autofac\src\Autofac\Core\Resolving\ResolveOperation.cs:line 83
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) in C:\projects\autofac\src\Autofac\ResolutionExtensions.cs:line 1041 at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable1 parameters) in C:\projects\autofac\src\Autofac\ResolutionExtensions.cs:line 814
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at DShop.Common.RabbitMq.BusSubscriber..ctor(IApplicationBuilder app) in C:\Users\Hossein\Desktop\Repository\Microservice\DNC\DNC-DShop.Common\src\DShop.Common\RabbitMq\BusSubscriber.cs:line 32
at DShop.Common.RabbitMq.Extensions.UseRabbitMq(IApplicationBuilder app) in C:\Users\Hossein\Desktop\Repository\Microservice\DNC\DNC-DShop.Common\src\DShop.Common\RabbitMq\Extensions.cs:line 25
at DShop.Api.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime, IConsulClient client, IStartupInitializer startupInitializer) in C:\Users\Hossein\Desktop\Repository\Microservice\DNC\DNC-DShop.Api\src\DShop.Api\Startup.cs:line 91
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
[20:17:35 FTL] Application startup exception
Autofac.Core.DependencyResolutionException: An exception was thrown while activating ?:RawRabbit.IBusClient. ---> RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable ---> System.IO.IOException: connection.start was never received, likely due to a network timeout
at RabbitMQ.Client.Framing.Impl.Connection.StartAndTune()
at RabbitMQ.Client.Framing.Impl.Connection.Open(Boolean insist)
at RabbitMQ.Client.Framing.Impl.AutorecoveringConnection.Init(IFrameHandler fh)
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 RawRabbit.Channel.ChannelFactory.ConnectAsync(CancellationToken token)
at RawRabbit.DependencyInjection.RawRabbitDependencyRegisterExtension.<>c.<AddRawRabbit>b__0_3(IDependencyResolver resolver)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.<>c__DisplayClass4_02.<AddSingleton>b__0() at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode)
at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy1.CreateValue()
at RawRabbit.DependencyInjection.SimpleDependencyInjection.GetService(Type serviceType, Object[] additional)
at RawRabbit.DependencyInjection.SimpleDependencyInjection.GetService[TService](Object[] additional)
at RawRabbit.Instantiation.InstanceFactory.Create()
at DShop.Common.RabbitMq.Extensions.<>c.<ConfigureBus>b__2_1(IComponentContext context) in C:\Users\Hossein\Desktop\Repository\Microservice\DNC\DNC-DShop.Common\src\DShop.Common\RabbitMq\Extensions.cs:line 89
at Autofac.Builder.RegistrationBuilder.<>c__DisplayClass0_01.<ForDelegate>b__0(IComponentContext c, IEnumerable1 p) in C:\projects\autofac\src\Autofac\Builder\RegistrationBuilder.cs:line 62
at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters) in C:\projects\autofac\src\Autofac\Core\Activators\Delegate\DelegateActivator.cs:line 71 at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable1 parameters, Object& decoratorTarget) in C:\projects\autofac\src\Autofac\Core\Resolving\InstanceLookup.cs:line 118
--- End of inner exception stack trace ---
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable1 parameters, Object& decoratorTarget) in C:\projects\autofac\src\Autofac\Core\Resolving\InstanceLookup.cs:line 136 at Autofac.Core.Resolving.InstanceLookup.Execute() in C:\projects\autofac\src\Autofac\Core\Resolving\InstanceLookup.cs:line 85 at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable1 parameters) in C:\projects\autofac\src\Autofac\Core\Resolving\ResolveOperation.cs:line 130
at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable1 parameters) in C:\projects\autofac\src\Autofac\Core\Resolving\ResolveOperation.cs:line 83 at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) in C:\projects\autofac\src\Autofac\ResolutionExtensions.cs:line 1041
at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters) in C:\projects\autofac\src\Autofac\ResolutionExtensions.cs:line 814
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider) at DShop.Common.RabbitMq.BusSubscriber..ctor(IApplicationBuilder app) in C:\Users\Hossein\Desktop\Repository\Microservice\DNC\DNC-DShop.Common\src\DShop.Common\RabbitMq\BusSubscriber.cs:line 32
at DShop.Common.RabbitMq.Extensions.UseRabbitMq(IApplicationBuilder app) in C:\Users\Hossein\Desktop\Repository\Microservice\DNC\DNC-DShop.Common\src\DShop.Common\RabbitMq\Extensions.cs:line 25
at DShop.Api.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime applicationLifetime, IConsulClient client, IStartupInitializer startupInitializer) in C:\Users\Hossein\Desktop\Repository\Microservice\DNC\DNC-DShop.Api\src\DShop.Api\Startup.cs:line 91
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
`
You solved it. I also met this mistake
Hello! I didn't understand how you solved the problem, could you please tell me how?
This means that the app can't connect to Rabbit AMQP api, which should be running on localhost:5672. I had the same issue when I ran the projects with Docker. My solution was to change "hostnames" in appsettings.json, from "localhost" to "host.docker.internal".
Thanks @evgenirusev - I was trying to get the RabitMq "Hello World" tutorial to work and could not figure out why is it not working.
This is what worked for me:
-
In Docker Terminal "Client" to make new Image - docker run -d --hostname my-rabit --name ecomm-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3
-
Than I copied the IP which is "192.168.99.100:15672" with the port :15672 and used that in the RabitMq as hostname - "Copied from the docker kitematic app"
-
In RabitMQ Console App Send And Receive - factory.HostName = "192.168.99.100";
-
In RabitMQ Console App Send And Receive - factory.Port = AmqpTcpEndpoint.UseDefaultPort;
thanks @evgenirusev for me "host.docker.internal" worked.
In my situation I have a docker desktop running with linux container and rabbitmq:3-management on it, then I created a dotnet core webapi with VS 20219.
Now when I am running the code it is working
- "localhost" on IIS Express
- "localhost" on Docker build from Visual Studio
- "host.docker.internal" on Docker build from Visual Studio
But not working in this scenario "host.docker.internal" on Docker with docker build command docker build -t mytagImage . docker run -d -p 7384:80 mytagImage
Hi, I created a small application using .netcore and rabbitmq and created the image in docker for both of them using below docker-compose code -
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<TraceSample>(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);
//}
//catch (Exception)
//{
// Debug.WriteLine(count);
// count++;
//}
}
i am new to docker . please help me to understand the issue and how to resolve it
run rabbitmq on docker. docker run -p 5672:5672 rabbitmq
This means that the app can't connect to Rabbit AMQP api, which should be running on localhost:5672. I had the same issue when I ran the projects with Docker. My solution was to change "hostnames" in appsettings.json, from "localhost" to "host.docker.internal".
Facing the same issues, this solves my problems for persistent connection
evgenirusev 's solution works ! thank you Evgeni Rusev
This means that the app can't connect to Rabbit AMQP api, which should be running on localhost:5672. I had the same issue when I ran the projects with Docker. My solution was to change "hostnames" in appsettings.json, from "localhost" to "host.docker.internal".
It works
Isso significa que o aplicativo não pode se conectar ao Rabbit AMQP api, que deve ser executado no localhost: 5672. Eu tinha o mesmo problema quando dirigi os projetos com o Docker. Minha solução foi mudar "hostnames" em appsettings.json, de "localhost" para "host.docker.internal".
Its Work!