Parsa Saei
Parsa Saei

Reputation: 1443

RabbitMQ Connection Error " None of the specified endpoints were reachable"

I installed rabbitmq service on the server and on my system. I want to use RPC pattern:

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();

I have an error on creating connection with this message:
None of the specified endpoints were reachable

When I use it on localhost instance of the server it works, but when I create the connection from local to that server,it returned the error. It not work with local ip and username and password of the my local computer.


Can anyone help me?

Upvotes: 33

Views: 119275

Answers (14)

Alimur Razi Rana
Alimur Razi Rana

Reputation: 480

In my case, after doing everything mentioned in above questions, when I update docker desktop and use latest rabbitmq: management, then connected perfectly.

Upvotes: 0

Soleco
Soleco

Reputation: 191

If the project is dockerized:

host.docker.internal (or appropriate URL...) should be used instead of localhost.

Upvotes: 4

Parsa Saei
Parsa Saei

Reputation: 1443

As this question mentioned.
After I installed RabbitMQ, I enabled management tools on the server and on my local computer with this:

rabbitmq-plugins enable rabbitmq_management

Then I restarted RabbitMQ service from services.msc
I could see the Rabbitmq management at http://localhost:15672
I logged in to rabbit management with user:guest and pass:guest
I added my favorite user pass with administrator access, so it worked.

Upvotes: 27

Joe Phillips
Joe Phillips

Reputation: 51120

My issue was that I created a user of guest with password guest and apparently that does not work. Once I chose a different username and password, it worked for me.

Upvotes: 0

kendolew
kendolew

Reputation: 506

Misleading error. The local version works ok but the remote server didn't. Turned out I did not supply the credentials i.e. username and password which are mandatory for remote server. Local server happily connects without them.

Upvotes: 1

jasmin
jasmin

Reputation: 209

Don't know if it helps you but it happen after update RabbitMQ.Client from 5.1.2 to 5.2.0 for .net 4.6.1. If you rise target framework to 4.8 it goes through.

Upvotes: 0

Gourav
Gourav

Reputation: 1

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(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

Upvotes: 0

Nitin Gupta
Nitin Gupta

Reputation: 141

I was also facing the same issue and later realized I have to open both ports i.e. 15672 and 5672.

The below command works for me in the docker container model.

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

Code snippet:

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

or

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

Upvotes: 14

fahadash
fahadash

Reputation: 3281

In our case it was an assembly binding failure of System.Threading.Tasks.Extensions, our exception logger was not logging the 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

Very poor misleading error message.

Upvotes: 4

MaPi
MaPi

Reputation: 1601

I've been experiencing this very issue, and in the end it was just about having provided the URI as lowercase, while the name of the machine was uppercase.

As it took a couple of hours to figure it out, I thought it might help someone else.

Upvotes: 0

Avnish Patel
Avnish Patel

Reputation: 141

1) Open RabbitMQ Command Promp

2) Change path to "C:\Program Files\RabbitMQ Server\rabbitmq_server-3.6.10\sbin" where rabbitmq_server installed.

3) Run following commamd : rabbitmq-plugins enable rabbitmq_management

If Firewall has blocked it, then popup display. Allow Firewall for this.

now you can access in browser.

Upvotes: 1

fancky
fancky

Reputation: 41

Do not use guest. Create your own account and password, and in http://localhost:15672/#/users , ensure "can access virtual hosts " is "/"

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

Upvotes: 4

dougajmcdonald
dougajmcdonald

Reputation: 20047

By default as you say RabbitMQ will listen on 5672 but this can be changed, if you have a look at your config (on the MQ server) you should find a section:

rabbit.tcp_listeners

which will detail the port being used. Check it's what you think it is.

Also, are you using IPv4 or IPv6? you may need to have additional config to support both.

Have a read of this:

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

Upvotes: 1

Gabriele Santomaggio
Gabriele Santomaggio

Reputation: 22682

it means that the client can't reach the server 158.2.14.42 and default vhost /.

Maybe a firewall configuration

Upvotes: 1

Related Questions