I use NServiceBus in my own process (therefore not using Generic Host), and I would like to have several message handlers for messages in a specific order. For Generic Host, you would do ISpecifyMessageHandlerOrdering , but I donβt know how to do this when hosting my own NServiceBus process, since this interface is defined in NServiceBus.Host.exe , and I could not find another way to do this.
The purpose of this is to authenticate the user: before calling the actual message handler, I would first want to authenticate the sender of the message, which will happen in another, more general, message handler. The message will be of a type that contains the encrypted username and password and / or session identifier. This type will be used for almost all commands sent to the server (everything except the login, I think). Is this a way to authenticate users using NServiceBus?
He currently takes the second handler, but not in the correct order.
Update
As David suggested, I tried to create an IMessageModule and read the headers from CurrentMessageContext to authenticate the user.
Here I ran into some problems:
- The first time a message is sent,
bus.CurrentMessageContext is null . Each time after that, it fills correctly, and I can read the headers. - Calling
bus.DoNotContinueDispatchingCurrentMessageToHandlers when the user is not authenticated does not stop calling message handlers. Also, bus.Return(errorCode) does not exist. Are there any other ways I can do this?
source share