Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does MessageEndpointMappings know to setup a subscription vs outgoing messages?

Tags:

nservicebus

I see MessageEndpointMappings section in my App.config and it just keeps confusing me.

Sometimes it looks like it sets of a client to subscribe to another queue (like this one does):

<UnicastBusConfig>
 <MessageEndpointMappings>      
   <add Messages="MyServiceBus.MessageHub.Contracts" Endpoint="MessageHub"/>
 </MessageEndpointMappings>
</UnicastBusConfig>

But other times it seems to be used to configure outgoing messages to other queues:

<UnicastBusConfig>
 <MessageEndpointMappings>      
   <add Messages="ServiceBus.MessageHub.InternalMessages" Endpoint="MessageHub"/>
 </MessageEndpointMappings>
</UnicastBusConfig>

But really, there is no difference between the two of them. So how does it know when to setup a subscription and when to setup for sending messages?

Or is it really doing both all the time and I just don't use both?

like image 230
Vaccano Avatar asked Jan 04 '12 22:01

Vaccano


1 Answers

Essentially, what you're declaring with the MessageEndpointMappings element, is "who is the owner of the specified messages?"

Another way to view it, is that this is the direction of the service dependency - not the message flow, because that is determined by whether messages get Sendt or Publishd.

Therefore, in order to be able to send messages and subscribe to messages from a given service, you declare an endpoint mapping in the sender/subscriber end.

And then, when the sender/subscriber has an endpoint mapping that points to another service and a handler for a message included in that endpoint mapping, NServiceBus is nice enough to automatically subscribe to that message (unless you disable the auto-subscription with DoNotAutoSubscribe()) - because, logically, that must mean that the sender/subscriber wishes to subscribe to the given message.

When you think about it this way, I think it makes sense. Hope you feel so too :)

like image 66
mookid8000 Avatar answered Oct 02 '22 22:10

mookid8000