我已經使用MassTransit實現了一個簡單的發佈者/消費者集,並且我希望讓消費者從同一個隊列中讀取消息。但是,當我運行它時,我看到大部分消息被髮送到錯誤隊列中,而不是被消耗掉。從我見過的討論(SO,Forum),這應該是非常簡單的RabbitMQ(只是指向相同的隊列),但它不工作。是否應該設置其他配置?與Rabbit競爭地下運輸消費者MQ
這裏是我的出版商
public class YourMessage { public string Text { get; set; } }
public class Program
{
public static void Main()
{
Console.WriteLine("Publisher");
Bus.Initialize(sbc =>
{
sbc.UseRabbitMqRouting();
sbc.ReceiveFrom("rabbitmq://localhost/test_queue");
});
var x = Console.Read();
for (var i = 0; i <= 1000; i++)
{
Console.WriteLine("Message Number " + i);
Bus.Instance.Publish(new YourMessage { "Message Number " + i });
}
}
}
和我的消費
public class YourMessage { public string Text { get; set; } }
public class Program
{
public static void Main()
{
Console.WriteLine("Consumer");
Bus.Initialize(sbc =>
{
sbc.UseRabbitMqRouting();
sbc.ReceiveFrom("rabbitmq://localhost/test_queue");
sbc.Subscribe(subs =>
{
var del = new Action<IConsumeContext<YourMessage>,YourMessage>((context, msg) =>
{
Console.WriteLine(msg.Text);
});
subs.Handler<YourMessage>(del);
});
});
while (true) { }
}
}