Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I set rebus up for one producer and many consumers

I am going through the samples and reading the docs but I am still not sure of how to configure rebus for my scenario (or that using the bus is a good fit).

I have one producer of Tasks to do, lets say ImportOrder and CalculateOrderPrice

I want to dump messages from the producer and queue lots of these messages. I want two clients that listens to ImportOrder, and 10 clients that listens to CalculatePriceOfOrder. I do not want the same order to go to multiple endpoints at the same time, I am trying to spread the workload.

Producer config so far:

 <rebus inputQueue="publisher.input" errorQueue="publisher.error" workers="1" maxRetries="5">

var adapter = new BuiltinContainerAdapter();
            Configure.With(adapter)
                   .Logging(l => l.Log4Net())
                        .Transport(t => t.UseMsmqAndGetInputQueueNameFromAppConfig())
                        .Subscriptions(s => s.StoreInXmlFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "rebus_subscriptions.xml")))
                        .MessageOwnership(d => d.FromRebusConfigurationSection())
                        .CreateBus()
                        .Start();

Consumer config so far:

<rebus inputQueue="calcserver1.input" errorQueue="calcserver1.error" workers="1" maxRetries="5">
<endpoints>
  <add messages="Messages.RecalculateContractMessage,  Messages" endpoint="[email protected]"/>
</endpoints>

Configure.With(adapter)
               .Logging(l => l.Log4Net())
                .Transport(t => t.UseMsmqAndGetInputQueueNameFromAppConfig())
                .MessageOwnership(d => d.FromRebusConfigurationSection())
                .CreateBus()
                .Start();

        adapter.Bus.Subscribe<RecalculateContractMessage>();

I cant seem to configure this setup, it does not really matter if I use msmq or sqlserver.

  • Does rebus (or any servicebus type of solution) sound like a good fit here?
  • Should I use pub/sub or plain Send pattern? And will that choice affect if messages gets processed by only one endpoint at the time or several?
  • Could anyone point me to a good example or explain how to set this scenario up?
like image 603
Jon Avatar asked Feb 07 '14 13:02

Jon


1 Answers

I'll answer your questions one by one:

  • Does rebus (or any servicebus type of solution) sound like a good fit here?

Yes, a service bus can help you deal with lots of stuff (e.g. serialization, threading, etc.) that you would otherwise have to somehow handle on your own.

  • Should I use pub/sub or plain Send pattern? And will that choice affect if messages gets processed by only one endpoint at the time or several?

In this case, it sounds to me like you're in need of a competing consumers type of distribution of your tasks.

This is NOT pub/sub - pub/sub implies 0..* consumers for each message instance, but you want exactly one recipient for each task. Therefore, you would bus.Send the tasks in this case.

  • Could anyone point me to a good example or explain how to set this scenario up?

I've written several blog posts in an attempt to show how you can scale out the handling of your workload with Rebus with examples for the different supported transports.

It should be fairly easy for you to get started by looking at the posts and use e.g. SQL Server as your transport.

like image 166
mookid8000 Avatar answered Nov 01 '22 10:11

mookid8000