同样,它应该很简单,但是找不到任何有关它的文档

在我以前的question中,我在docker中运行Rabbitmq容器时遇到问题。解决了,但是现在又出现了

容器是用这一行创建的

docker run -d --hostname my-rabbit --name some-rabbit -p 15672:15672 rabbitmq:3-management

我试图创建一个简单的控制台应用程序来检查消息发送的工作方式(来自base tutorial):
var factory = new ConnectionFactory()
{
  HostName = "localhost",
  Port = 15672
};

using (var connection = factory.CreateConnection())
{
  using (var channel = connection.CreateModel())
  {
    channel.QueueDeclare("Test", false, false, false, null);

    var mess = new RepMessage()
    {
       ConnectionString = "TestingString",
       QueueID = 5
    };

    var jsonified = JsonConvert.SerializeObject(mess);
    var messBody = Encoding.UTF8.GetBytes(jsonified);
    channel.BasicPublish("", "Test", null, messBody);

    Console.WriteLine(string.Format("Message with ConStr={0}, QueueID={1} has been send", mess.ConnectionString, mess.QueueID));
  }
}

结果是,它不起作用。
我收到异常None of the specified endpoints were reachable和内部异常作为connection.start was never received, likely due to a network timeout
如果我删除端口,则内部异常会转换为No connection could be made because the target machine actively refused it 127.0.0.1:5672
我想念的是,这个示例不应该与docker一起使用吗?

最佳答案

端口15672是Rabbitmq管理插件Web界面的端口。当您向兔子发送消息时-您需要连接到其他端口(默认情况下-5672)。因此,更改您的代码以连接到该端口,然后通过-p 5672:5672将其映射到docker中。

08-16 13:27