Problem with accessing RabbitMQ - different hostname
// there are so many repositories, that I don't know where I should put this issue ;)
I created the whole infrastructure by docker compose and tried to run the DShop.Api. And I encountered an error: An exception of type 'RabbitMQ.Client.Exceptions.BrokerUnreachableException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'None of the specified endpoints were reachable'
I investigated that issue and found out that application uses appsettings.development.json file, where there is RabbitMQ configuration - "hostnames": [ "rabbitmq" ]
Unfortunately all resources are created by docker compose on localhost (there is no mentioning a different host), and application cannot connect to RabbitMQ which causes error.
When i hacked RabbitMQ configuration's resolving by rawRabbitConfiguration.Hostnames[0] = "localhost"; line in DShop.Common application started without problem.
My question - is this my problem with running this repo or did you make a mistake with configuration with RabbitMQ?
How did you run DShop.Api? Was it via Docker image or Dotnet CLI?
As far as I remember the default appsettings.json contains localhost as a hostname, so you should be able to run it using dotnet run command. If you want to use Docker then I think you should go for docker-compose-local.yaml. That is because RabbitMQ container needs to be linked to API (in order to be visible as rabbitmq service).
Anyway, let me know how did you try to run it ;)
I tried to run the application in 2 different approaches :D
-
I run DShop.Api from Visual Studio Code. It automatically adds
launch.jsonwith"ASPNETCORE_ENVIRONMENT": "Development"so application tries to reach RabbitMQ atrabbitmq. -
I run
docker-compose-infrastructure.yamland then I run DShop.Api in Docker byDockerfile. But then it doesn't see RabbitMQ because it is in a different network.
For the second one, I can add a network to compose files to allow running different docker containers with a connection to this network.
I'm not quite sure why do we have rabbitmq in Development. Maybe @spetz could answer that. I think we should simply change it to localhost. Would that be ok for you?
Yes :)
But what about option 2 - is it OK to add network information to compose files?
@GooRiOn For my instance using default RabbitMQ settings and changing to "hostnames": [ "localhost" ] in appsettings.json file worked.