我正在为RabbitMQ运行所有ServiceStack测试,但就我而言,我无法通过这个“Publishing_message_to_fanout_exchange_publishes_to_all_queues”来通过。经过一番挖掘和阅读后,我发现:
下面这两个语句实际上做了同样的事情,将队列绑定到交换(主题)并提供路由密钥,但路由密钥不同,因此只有一个队列获得发布的消息它,所以测试总是失败。
RegisterTopic(channel, QueueNames<HelloRabbit>.Out);
RegisterQueue(channel, QueueNames<HelloRabbit>.In, exchange: ExchangeTopic);
我希望有人可以告诉我这个测试是否过去了。
谢谢你,Stephen
答案 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);
}
}