Search code examples
c#.netnservicebus

Specify Message Handler Ordering in NServiceBus 6.x


ISpecifyMessageHandlerOrdering interface is obsolete in NServiceBus 6.x.

Documentation tells to specify order by calling ExecuteTheseHandlersFirst method on endpointConfiguration.

I am upgrading NSB from 5.x to 6.x. In solution I have endpointConfiguration in one core library and many handlers in other libraries. Is there a way to specify handler ordering in these other libraries (5.x manner)?


Solution

  • If I'm understanding you correctly, your problem comes from the fact that an ISpecifyMessageHandlerOrdering implementation could be placed anywhere and be picked up by assembly scanning, where the EndpointConfiguration is in a predefined spot, and not where your handlers are. Correct?

    If that's the case, I think the INeedInitialization interface would be the right extension point for you. It gives you access to the EndpointConfiguration and is picked up by assembly scanning.

    Alternatively, there's a community project called NServiceBus.HandlerOrdering that allows you to express handler orderings more expressively right on the handler, adding interfaces like IWantToRunAfter<OtherHandler>. Here's a sample showing how that project works.