我連接RabbitMQ的代碼如下:
var connectionFactory = new ConnectionFactory() { HostName = "192.168.1.5", Port = 15672, UserName = "guest", Password = "gues", VirtualHost = "/" };
出現的問題如下:
RabbitMQ.Client.Exceptions.BrokerUnreachableException
HResult=0x80131620
Message=None of the specified endpoints were reachable
Source=RabbitMQ.Client
StackTrace:
在 RabbitMQ.Client.ConnectionFactory.CreateConnection(IEndpointResolver endpointResolver, String clientProvidedName)
在 RabbitMQ.Client.ConnectionFactory.CreateConnection(String clientProvidedName)
在 RabbitMQ.Client.ConnectionFactory.CreateConnection()
在 SJ.RabbitMQConsoleTest.Normal.RabbitMQConnection.SendMessage()
解決方案:
去官網(http://rabbitmq.mr-ping.com/tutorials_with_csharp/HelloWorld.html)查,按照官網的去操作就可以解決了;
把代碼改為:
var connectionFactory = new ConnectionFactory()
{
HostName = "localhost"
};
問題解決了!