2
votes

I have few message handlers (IHandleMessage) handling different messages in a project. The messages are not consumed by handlers from different endpoints. They are consumed from the endpoint mentioned in the EndpointConfig or from the endpoint with the name same as the namespace of the project. How can I have handlers consuming messages as per set of endpoints defined in MessageEndpointMappings section?

For example, I have two message types. Message1 and Message 2 in project Contracts and two handlers (IHandleMessage), Message1Handler and Message2Handler in project Handlers.

I am using RabbitMq transport of the NServiceBus. I want these handlers to consume messages from their respective message queues, i.e. Message1Handler from Contracts.Message1 queue and Message2Handler from Contracts.Message2 queue.

<MessageEndpointMappings>
      <add Assembly="Contracts" Type="Contracts.Message1" Endpoint="Contracts.Message1" />
      <add Assembly="Contracts" Type="Contracts.Message2" Endpoint="Contracts.Message2" />
  </MessageEndpointMappings>

These endpoint mappings in Handler project does not work. The messages are not consumed. The messages are either consumed from Handler queue (same as namespace of the project) or EndpointName mentioned in the EndpointConfig.cs.

What is the use of MessageEndpointMappings in case of handlers?

I am using NServiceBus 5.2.0

1
The MessageEndpointMapping configures where messages need to be sent based on a message type. It has no effect on receiving. The behaviour that you currently observe is correct. If you need handlers to process different queues, you need two different endpoints. Currently, you have only one.Alexey Zimarev
@AlexeyZimarev, to clarify, MessageEndPointMappings indicates where a message comes from in the case of events, and point to where a message has to go to in case of a command.Yannick Meeus
It seems you are just getting started with NServiceBus, the best resource to get started is our documentation at docs.particular.net specifically look at docs.particular.net/samples/step-by-step and docs.particular.net/nservicebus/messaging/… ---------- If you have any further questions feel free to ask us in our forum at groups.google.com/forum/#!forum/particularsoftwareJohn Simons
Thanks Alexey and Yannick for your response.Nikhil
If I do a Bus.Send and send Message2 in Message1Handler, then the message is not sent as per the endpoints in MessageEndpointMapping. In this case I am sending the message, it still sends to the endpoint mentioned in the Endpointconfig instead of endpoint mapping. So how do I mention if my handler wants to send a response message to another endpoint based on the type of the message?Nikhil

1 Answers

0
votes

Thanks Alexey, Yannick and John for help.

Just to mention the answer to the question:

Messages are sent as per the mappings in the MessageEndpointMappings. This section does not have any role in the way messages are received. Messages are received at the endpoint set in the EndpointConfig.cs (or at the queue same as namespace of the project).