Question

I've implemented a simple publisher/consumer set with MassTransit, and I want to have the consumers read the messages from the same queue. However, when I run it, I see a large portion of the messages sent to the error queue instead of being consumed. From the discussions I've seen (SO, Forum), this should be really really simple with RabbitMQ (just point to the same queue), but it's not working. Is there an additional configuration that should be set?

Here's My Publisher

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 });
        }
    }
}

And My Consumer

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) { }
    }
}
Was it helpful?

Solution

The receiver/consumer and publisher cannot be on the same queue. If you want competing consumers have multiple instances of the consumer running against the same queue.

We have documentation, but this section is currently lacking, so I understand your confusion: http://readthedocs.org/docs/masstransit/en/latest/configuration/gotchas.html#how-to-setup-a-competing-consumer If you succeed, help with the documentation would be wonderful.

OTHER TIPS

So, it looks like the solution was to change the line in the publisher:

 sbc.ReceiveFrom("rabbitmq://localhost/test_queue"); 

To something like:

 sbc.ReceiveFrom("rabbitmq://localhost/test_queue_publisher"); 

This prevented the publishers from competing for messages they weren't configured to consume.

Just found an example on GitHub https://github.com/khalidabuhakmeh/MassTransit.ScaleOut ...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top