I am trying to get a .Net 4.7.2 web application to connect to a RabbitMQ server running in a (Windows) Docker container (on the same machine as the web app is running in).
UPDATE: Using a non-Docker version of RabbitMQ does not solve the problem either. The console connects to the non-Docker RabbitMQ and can publish a message, but the .Net 4.7.2 web app still fails.
I am using the RabbitMQ.Client 6.2.4 (VMWare) with the following connection code:
ConnectionFactory connectionFactory = new ConnectionFactory();
Uri uri = new Uri("amqp://dan:dan@localhost:5672/");
connectionFactory.Uri = uri;
var theConnection = connectionFactory.CreateConnection();
(Note I have also tried with the same results:
var factory = new ConnectionFactory() { HostName = "localhost", Port = 5672, VirtualHost = "/", UserName = "dan", Password = "dan" };
using (var connection = factory.CreateConnection())
)
User dan exists as an administrator and has rights to the virtual host.
I am receiving the following error:
{"None of the specified endpoints were reachable"}
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146232800
HelpLink: null
InnerException: {"connection.start was never received, likely due to a network timeout"}
Message: "None of the specified endpoints were reachable"
Source: "RabbitMQ.Client"
StackTrace: " at RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)rn at XXXX.Common.BackgroundSubmit.SubmitBackgroundProcess.<>c.<SubmitJob>b__0_0(String connectionURI) in C:\XXXX.Common\BackgroundSubmit\BackgroundSubmitProcess.cs:line 71"
TargetSite: {RabbitMQ.Client.IConnection CreateConnection(RabbitMQ.Client.IEndpointResolver, System.String)}
The RabbitMQ log reports this activity:
2022-05-18 02:18:59.346295+00:00 [info] <0.1164.0> accepting AMQP connection <0.1164.0> (172.19.0.1:55538 -> 172.19.0.2:5672)
2022-05-18 02:18:59.443173+00:00 [warning] <0.1164.0> closing AMQP connection <0.1164.0> (172.19.0.1:55538 -> 172.19.0.2:5672):
2022-05-18 02:18:59.443173+00:00 [warning] <0.1164.0> client unexpectedly closed TCP connection
I created a small console application and that application works fine – it can connect (and subsequently produce a message to a queue). This console application is .NET 6.0.
I have tried using the actual IP address of my machine as well as 127.0.0.1 and the console connects but the web app does not.
I looked at several tickets and thought maybe this was a good lead:
https://stackoverflow.com/questions/68011963/factory-createconnection-generates-a-none-of-the-specified-endpoints-were-reac
this said make sure that System.Threading.Tasks.Extension, System.Threading.Channels and System.Memory are all the same versions in all referenced projects, and they are.
Also tried using rabbitmq_localdev as the rabbit host name in the URI.
Any suggestions would be greatly appreciated!
Thanks,
D
Here is the docker-compose .yaml if it helps:
version: "3.2"
services:
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: 'rabbitmq'
ports:
- 5672:5672
- 15672:15672
# Expose 15672 for the management console, localhost:15672, guest/guest
# Expose 5672 for the qmpq port
# https://stackoverflow.com/questions/30747469/how-to-add-initial-users-when-starting-a-rabbitmq-docker-container
hostname: rabbitmq_localdev
volumes:
- ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
- ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq
networks:
- rabbitmq_go_net
networks:
rabbitmq_go_net:
driver: bridge
2
Answers
For those landing here in the future, I was able to resolve this.
My solution had multiple projects. The MVC project that had the RabbitMQ connectivity work in it had RabbitMQ.Client as a NuGet package, but the other project did not. I added RabbitMQ.Client to the other project via NuGet and it solved the problem.
I’ll rephrase the accepted answer.
If you have a
RabbitMQ
client in the library project, add the reference of theRabbitMQ.Client
Nuget package also to the root of the main project (MVC project, Job, WCF service, e.t.c). This will resolve the issue.