I have an Endpoint with a Handle method. I would like to do something immediately before and immediately following Handle. I was able to get the step working before by imolementing LogCommandEntryBehavior : Behavior<IIncomingLogicalMessageContext>. What needs to be implemented to happen immediately following Handle?
How do you register a behavior to execute after the "Handle" method in NServiceBus 6?
784 views Asked by Adam Modlin At
1
In NServiceBus Version 6, the pipeline consists of a series of Stages, each one nested inside the previous like a set of Russian Dolls. For an incoming message, the stages are (in order):
ITransportReceiveContext,IIncomingPhysicalMessageContext,IIncomingLogicalMessageContext, andIInvokeHandlerContextWhen you create a behavior within a stage, you get passed a delegate called
next(). When you callnext()you execute the next behavior in the pipeline (which may move the pipeline to the next stage). The call tonext()returns aTaskwhich indicates when this inner part of the pipeline is done.That gives you the opportunity to invoke your code before moving on to the next stage, and invoke more code after the next stage has been completed like this:
If you want to log information about the handling of a message, I recommend looking at the
IInvokeHandlerContextstage. It contains information about how the message was handled and will be called once for every handler that is invoked (in cases where you have multiple). If you don't need info at that level thenIIncomingLogicalMessageContextis probably all you need.You can read more about the Version 6 pipeline in the Particular Docs site: