Search code examples
nservicebusnservicebus4

NServiceBus - Difference between DefineEndpointName and app.config MessageEndpointMappings


Would somebody be able to explain what the difference is between configuring the EndpointName in Configure.DefineEndpointName and specifying it in the app.config under MessageEndpointMappings?

i.e.

.DefineEndpointName("Something.MessageQueue")

And

 <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Assembly="Something.Messages" Endpoint="Something.MessageQueue" />
    </MessageEndpointMappings>
  </UnicastBusConfig>

Solution

  • This sets the name of the current endpoint to "Something.MessageQueue":

    .DefineEndpointName("Something.MessageQueue")
    

    This tells the configured endpoint that when sending messages that reside in assembly Something.Messages, the destination endpoint to send them to is "SomethingServer.MessageQueue". I changed the endpoint name in your example to illustrate that they are different endpoints.

    <UnicastBusConfig>
        <MessageEndpointMappings>
          <add Assembly="Something.Messages" Endpoint="SomethingServer.MessageQueue" />
        </MessageEndpointMappings>
      </UnicastBusConfig>
    

    I should note that the endpoint names could be the same endpoints if you want to send a message to yourself (which can be useful from time to time).

    Edit

    Documentation links: