18
votes

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?

8
@RazvanDumitru , I do like that but still have the error. and code doesn't recognize FromEnvironmentparsa
@RazvanDumitru Thank you,your guidance helped me.parsa

8 Answers

17
votes

Thank you all. As this :
https://stackguides.com/questions/4987438/rabbitmq-c-sharp-connection-trouble-when-using-a-username-and-password
After I installed RabbitMQ, I enabled management tools at 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 loginned to rabbit management with user:guest and pass:guest
I added my favorite user pass with administrator access, so it worked.

1
votes

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

Maybe a firewall configuration

1
votes

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" 
};
1
votes

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.

1
votes

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.

1
votes

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" };
0
votes

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

0
votes

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.