In version 5 of nServiceBus I have a Behavior that keeps track of messages in flight.
In the Behavior I was able to access DeliveryOptions(SendOptions) and see the Destination Queue, in NSB 6 with the change to the Behavior I can't seem to access the destination of the message any more.
Does anyone know of to access the destination of an outgoing message from a Behavior?
Previous code in v5:
public class PendingCommandBehavior : IBehavior<OutgoingContext>
{
public void Invoke(OutgoingContext context, Action next)
{
var sendOptions = context.DeliveryOptions as Nsb.Unicast.SendOptions;
if (sendOptions != null && context.OutgoingMessage.MessageIntent == Nsb.MessageIntentEnum.Send)
{
var destinationEndpoint = sendOptions.Destination.Queue;
Code in v6:
public class PendingCommandBehavior : Behavior<IOutgoingSendContext>
{
public override async Task Invoke(IOutgoingSendContext context, Func<Task> next)
{
// context doesn't have any destination queue information???
The
IOutgoingSendContext
is too early in the pipeline to capture the physical destination. Each outgoing send operation will go through the following contexts (in order) in NServiceBus version 6:IOutgoingSendContext
IOutgoingLogicalMessageContext
IOutgoingPhysicalMessageContext
IRoutingContext
IBatchDispatchContext
(if you are sending from inside a message handler)IDispatchContext
After
IOutgoingSendContext
a routing strategy is selected but it is not converted into a physical address until afterIRoutingContext
.For that reason, if you want to track physical addresses, the best bet is to sit in the
IDispatchContext
. This context will contain a collection ofTransportOperation
s, each of which has anAddressTag
. This will either be an instance ofUnicastAddressTag
with aDestination
or an instance ofMulticastAddressTag
with aMessageType
.Here is some code to get you started:
For more info about the NServiceBus version 6 pipeline, see Steps, Stages and Connectors in the NServiceBus documentation.