A Curious Mind
#tastic

MassTransit: How to acheive 'Competing Consumers'

Thursday, October 09, 2008 2:39 PM
Hi Adam,
How can multiple services subscribe to the same message but only have it delivered once? I am thinking of redundancy and load balancing scenarios where I have multiple clients processing messages.

I think that you are referring to a competing consumer pattern. Assuming this is correct this is how I would go about solving it in MT.

In masstransit, we have the concept of a control bus as being different from the 'data bus'. You can see this in the XML below

    <facility id="masstransit">
      <bus id="server"
              endpoint="msmq://localhost/mt_server">
        <subscriptionCache name="subscriptioncache.shared"/>
        <managementService heartbeatInterval="3" />
      </bus>
      <bus id="control"
              endpoint="msmq://localhost/mt_server_control">
          <subscriptionCache name="subscriptioncache.shared"/>
          <subscriptionService endpoint="msmq://localhost/mt_pubsub">
            <localEndpoint>msmq://localhost/mt_server</localEndpoint>
          </subscriptionService>
      </bus>
      <transports>
        <transport>MassTransit.ServiceBus.MSMQ.MsmqEndpoint, MassTransit.ServiceBus.MSMQ</transport>
      </transports>
    </facility>

Here you can see a snippet of the windsor masstransit facility where one 'autonomous component' is listening for data at 'msmq://localhost/mt_server' and is listening for control messages (things like subscription updates) at 'msmq://localhost/mt_server_control'. This setup will allow multiple consumers to happily exist. :) Each one listening for application messages at 'msmq://localhost/mt_server' and receiving at there own control endpoint 'msmq://localhost/mt_server1_control', 'msmq://localhost/mt_server2_control', etc.

I would also recommend that from an application development standpoint that your software be able to handle any given message more than once. As we move into a more distributed environment, the statement 'You will get this message at least once' becomes a helpful mantra, as it helps to avoid the pitfalls of the network.

Hope that helps

-d

Feedback

# re: MassTransit: How to acheive 'Competing Consumers'

I am not sure how to get competing consumers working. I have tried a number of different configuration.

Can you please give a full example configuration.

Regards
Taliesin

<!-- Configuration will result in sequential execution of messages by consumer -->
<bus id="server" endpoint="msmq://localhost/mt_server"/>

<bus id="controlA" endpoint="msmq://localhost/mt_server_control1">
<subscriptionService endpoint="msmq://localhost/mt_pubsub">
<localEndpoint>msmq://localhost/mt_server</localEndpoint>
</subscriptionService>
</bus>

<bus id="controlB" endpoint="msmq://localhost/mt_server_control2">
<subscriptionService endpoint="msmq://localhost/mt_pubsub">
<localEndpoint>msmq://localhost/mt_server</localEndpoint>
</subscriptionService>
</bus>

<!-- Configuration will result in sequential execution of messages by consumer -->
<bus id="server" endpoint="msmq://localhost/mt_server"/>

<bus id="control" endpoint="msmq://localhost/mt_server_control">
<subscriptionService endpoint="msmq://localhost/mt_pubsub">
<localEndpoint>msmq://localhost/mt_server</localEndpoint>
</subscriptionService>
</bus>

<!-- Configuration will result in parallel execution of messages by consumer -->
<bus id="serverA" endpoint="msmq://localhost/mt_server1"/>
<bus id="serverB" endpoint="msmq://localhost/mt_server2"/>

<bus id="controlA" endpoint="msmq://localhost/mt_server_control1">
<subscriptionService endpoint="msmq://localhost/mt_pubsub">
<localEndpoint>msmq://localhost/mt_server1</localEndpoint>
</subscriptionService>
</bus>

<bus id="controlB" endpoint="msmq://localhost/mt_server_control2">
<subscriptionService endpoint="msmq://localhost/mt_pubsub">
<localEndpoint>msmq://localhost/mt_server2</localEndpoint>
</subscriptionService>
</bus> 11/21/2008 9:59 AM | Taliesin Sisson

# re: MassTransit: How to acheive 'Competing Consumers'

I did not realize, that in order for competing consumers to work, I would need to insure that a Point-to-Point Channel was used and not a Publish-Subscribe Channel. A Publish-Subscribe Channel would just make copies of the message.

http://www.ubookcase.com/book/Addison.Wesley/Enterprise.Integration.Patterns.Designing.Building.And.Deploying.Messaging.Solutions/0321200683_ch10lev1sec7.html

Regards
Taliesin 12/2/2008 7:10 AM | Taliesin Sisson

Comments have been closed on this topic.