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

1

8

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?

Unhandled answered 4/1, 2012 at 22:47 Comment(0)
L
19

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 :)

Lobate answered 5/1, 2012 at 10:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.