如何修复失败的ServerStack RabbitMQ扇出交换测试,而不重写整个测试

时间:2014-10-09 04:14:13

标签: servicestack rabbitmq

我正在为RabbitMQ运行所有ServiceStack测试,但就我而言,我无法通过这个“Publishing_message_to_fanout_exchange_publishes_to_all_queues”来通过。经过一番挖掘和阅读后,我发现:

  1. 测试名称应更改为Topic,而不是扇出(ServiceStack框架内置功能不提供)。
  2. 测试文件中不需要RegisterQueue,RegisterTopic和RegisterDlq静态方法,您应该使用RabbitMqExtensions。
  3. 下面这两个语句实际上做了同样的事情,将队列绑定到交换(主题)并提供路由密钥,但路由密钥不同,因此只有一个队列获得发布的消息它,所以测试总是失败。

    RegisterTopic(channel, QueueNames<HelloRabbit>.Out);
    
    RegisterQueue(channel, QueueNames<HelloRabbit>.In, exchange: ExchangeTopic); 
    
  4. 我希望有人可以告诉我这个测试是否过去了。

    谢谢你,Stephen

1 个答案:

答案 0 :(得分:1)

此测试未正确重构,过去曾使用its commit history中的fanout交换。

just changed it使用扇出交换,如下所示:

[Test]
public void Publishing_message_to_fanout_exchange_publishes_to_all_queues()
{
    using (IConnection connection = mqFactory.CreateConnection())
    using (IModel channel = connection.CreateModel())
    {
        channel.RegisterFanoutExchange(ExchangeFanout);

        RegisterQueue(channel, QueueNames<HelloRabbit>.In, exchange: ExchangeFanout);
        RegisterQueue(channel, QueueNames<HelloRabbit>.Priority, exchange: ExchangeFanout);

        byte[] payload = new HelloRabbit { Name = "World!" }.ToJson().ToUtf8Bytes();
        var props = channel.CreateBasicProperties();
        props.SetPersistent(true);

        channel.BasicPublish(ExchangeFanout, QueueNames<HelloRabbit>.In, props, payload);

        var basicGetMsg = channel.BasicGet(QueueNames<HelloRabbit>.In, noAck: true);
        Assert.That(basicGetMsg, Is.Not.Null);

        basicGetMsg = channel.BasicGet(QueueNames<HelloRabbit>.Priority, noAck: true);
        Assert.That(basicGetMsg, Is.Not.Null);
    }
}