Last post Jul 23, 2018 08:48 AM by Pervaiz Khan
Jul 20, 2018 05:43 PM|Pervaiz Khan|LINK
I hope, this not wrong forum for my question. I am calling RabbitMQ from .ASP.NET core web API but it is giving me following error:
RabbitMQ.Client.Exceptions.BrokerUnreachableException: 'None of the specified endpoints were reachable'
ExtendedSocketException: No connection could be made because the target machine actively refused it 127.0.0.1:5672
I have following code which works perfectly for .NET Core Console app:
ConnectionFactory connectionFactory = new ConnectionFactory();
connectionFactory.Port = 5672;
connectionFactory.HostName = "localhost";
connectionFactory.UserName = ""; // User name
connectionFactory.Password = ""; //password
connectionFactory.VirtualHost = "/";
IConnection connection = connectionFactory.CreateConnection();
IModel channel = connection.CreateModel();
//Console.WriteLine(string.Concat("Connection open: ", connection.IsOpen));
channel.ExchangeDeclare("my.first.exchange", ExchangeType.Direct, true, false, null);
channel.QueueDeclare("my.first.queue", true, false, false, null);
channel.QueueBind("my.first.queue", "my.first.exchange", "");
Any suggestion please?
Jul 23, 2018 07:26 AM|Edward Z|LINK
Based on your previous post, you are laucnhing project from Docker.
To check whether it is related with Docker, I suggest you launch your web api project directly from VS, will you receive any error?
Jul 23, 2018 08:48 AM|Pervaiz Khan|LINK
Thank you for your response. I was able to fix this issue by:
1. Creating .NET Standard Library project for exposing RabbitMQ calling methods.
2. Calling methods of libaray (step 1) from Web Api.