Routing issue in Outbound message behavior

I’m getting some odd routing behaviour on sending additional messages in an outbound behaviour handler (specifically a Behavior<IOutgoingLogicalMessageContext>)

Let’s say I have services A, B and C.
All routes are set on the EndpointConfiguration object at service startup.

Service A is processing a Saga and needs to send a message to Service B
In Service A we register a Behavior<IOutgoingLogicalMessageContext> that contains some business logic, and will send an extra message to Service C using IOutgoingLogicalMessageContext.Send<IMessage>(m => …)

That works fine, the original message gets to B, the extra message gets to C.

If instead of sending from A to B though, we send a message from A back to itself using IMessageHandlerContext.SendLocal it doesn’t behave as we’d expect.
The same Behavior picks up the outgoing message, sends the extra message using the same logic and message type.
The original message gets to A, but the extra message is also delivered to A, not to C.

It looks like there’s some state in the IOutgoingLogicalMessageContext that causes it to ignore routing on all outgoing messages if the context was created by a call to SendLocal().

All this observed using NServiceBus 7.4.7 on NetCore5 in Azure docker images.

Hey @alunh ,

Thanks for the description, I was able to reproduce the described behavior. This definitely looks like a bug, I’ll keep you updated on the issue.

btw. as an immediate workaround, the routing should work correctly if you hard-code the message destination via sendOptions.SetDestination(...) passing the target endpoint queue address as the parameter.

Hey @alunh ,

I’ve raised a issue for this bug in the NServiceBus repository here: Default options from operations in outgoing behaviors might not be applied · Issue #6223 · Particular/NServiceBus · GitHub. We have prioritized this issue near the top of our list and will be working on it as soon as we can.

If the mentioned workaround doesn’t resolve the issue in the meantime, please let me know and we can see if there is another way to make this work till a fix has been released.

Thanks Tim, we’ll give those a go