Pergunta

I understand that Rebus is perfectly capable of transporting messages from point A to B (using MSMQ as the transport layer). To make things perfectly clear, is Rebus also capable of doing one-to-many messaging, i.e. messages sent from point A should end at both point B and C?

And if it is possible, how does it do it? I cannot see any centralised distribution site (a post-office), so I assume that the communication will consist of a channel from every endpoint to every other endpoint (so that in a network where a process has to communicate with 5 other endpoints, there will be 5 channels radiating out of this process). Can you confirm this assumption?

Foi útil?

Solução

Yes, Rebus is indeed capable of publishing messages to virtually any number of subscribers. It's true that MSMQ (at least in its most basic mode of operation) is a simple point-to-point channel, which is why there's a layer on top in order to implement true pub/sub.

The way it works, is that each subscriber has an endpoint mapping pointing to the publisher, and then each subscriber goes

bus.Subsribe<SomethingInterestingHappened>();

which causes an internal SubscriptionMessage to be sent the the publisher. The publisher must then remember who subscribed to each given message type, typically by storing this information in an SQL Server. All this happens automatically, it just requires that you configure some kind of subscription storage.

And then, when the time comes to publish something, the publisher goes

bus.Publish(new SomethingInterestingHappened { ... });

which will make Rebus look up all the subscribers of the given message type. This may be 0, 1 or more, and then the event will be sent to each subscriber's input queue.

You can read more about these things in the Rebus docs on the page about routing.

To give you a hint on how subscribers and publishers might be configured, check this out - this is a subscriber:

Configure.With(...)
    .Transport(t => t.UseMsmq....)
    .MessageOwnership(t => t.FromRebusConfigurationSection())
    (...)

which also has an endpoint mapping that maps a bunch of events to a specific publisher:

<endpoints>
    <add messages="SomePublisher.Messages" endpoint="publisher_input_queue" />
</endpoint>

and then the publisher might look like this:

Configure.With(...)
    .Transport(t => t.UseMsmq....)
    .Subscriptions(s => s.StoreInSqlServer(theConnectionString, "subscriptions")
                         .EnsureTableIsCreated())
    (...)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top