NServiceBus:指定信息秩序 [英] NServiceBus: specifying message order
问题描述
我在自己的过程中使用NServiceBus(这样的不可以使用通用主机),我想有多个消息处理程序的消息在一个特定的顺序。对于通用主机,你将实施 ISpecifyMessageHandlerOrdering
,但我不知道托管自己的NServiceBus进程的时候,因为该接口在 NServiceBus.Host.exe
,我一直没能找到另一种方式来做到这一点。
I'm using NServiceBus in it's own process (so not using the Generic Host) and I would like to have multiple message handlers for a message in a specific order. For the Generic Host, you would implement ISpecifyMessageHandlerOrdering
, but I don't know how to do this when hosting your own NServiceBus process since that interface is defined in NServiceBus.Host.exe
and I haven't been able to find another way to do this.
这样做的目的是验证用户身份:当调用实际的消息处理程序之前,我想先验证消息,这将在一个不同的,更通用,消息处理程序发生的发件人。该消息将包含加密的用户名和密码,和/或会话ID的类型。这种类型将用于发送到服务器,几乎所有的命令(一切,但登录我认为)。这是使用NServiceBus做用户认证的方式确定?
The purpose of this is user authentication: before the actual message handler is invoked, I would first like to authenticate the sender of the message, which would happen in a different, more generic, message handler. The message will be of a type that contains the encrypted user name and password and/or a session ID. This type will be used for almost all commands sent to the server (everything but login I think). Is this an OK way to do user authentication using NServiceBus?
目前,它拿起所述第二处理程序,但没有按正确的顺序
Currently, it picks up the second handler but not in the right order.
更新
正如大卫建议我尝试创建一个 IMessageModule
和从 CurrentMessageContext
来验证用户读取头。
As suggested by David I tried creating a IMessageModule
and reading the headers from the CurrentMessageContext
to authenticate the user.
我遇到了一些问题,在这里:
I ran into some problems here:
- 我第一次发送邮件时,
bus.CurrentMessageContext
是空
。之后每一次,它是填写正确,我可以读头。 - 电话
bus.DoNotContinueDispatchingCurrentMessageToHandlers
当用户没有通过验证不被调用停止消息处理程序。无论是做bus.Return(错误code)
。是否有其他方法,我能做到吗?
- The first time I send a message, the
bus.CurrentMessageContext
isnull
. Every time after that, it's filled in correctly and I can read the headers. - Calling
bus.DoNotContinueDispatchingCurrentMessageToHandlers
when the user is not authenticated does not stop the message handlers from being invoked. Neither doesbus.Return(errorCode)
. Are there other ways I can do that?
推荐答案
作为文档页面上的常见问题NServiceBus描述:
As described in the NServiceBus FAQ on the documentation page:
http://docs.particular.net/nservicebus/handlers/handler-ordering
我如何指定在处理程序被调用的顺序?
How do I specify the order in which handlers are invoked?
如果你正在写自己的主机:
If you're writing your own host:
NServiceBus.Configure.With()
...
.UnicastBus()
.LoadMessageHandlers(First<H1>.Then<H2>().AndThen<H3>().AndThen<H4>() //etc)
...
如果您使用的通用主机
public class EndpointConfig : IConfigureThisEndpoint, ISpecifyMessageHandlerOrdering
{
public void SpecifyOrder(Order order)
{
order.Specify(First<H1>.Then<H2>().AndThen<H3>().AndThen<H4>() //etc);
}
}
如果您只想指定单个处理器(用自己的主机)
If you only want to specify a single handler (with your own host)
NServiceBus.Configure.With()
...
.UnicastBus()
.LoadMessageHandlers<FIRST<YourHandler>>()
...
如果您只想指定单个处理器(与通用主机)
If you only want to specify a single handler (with the generic host)
public class EndpointConfig : IConfigureThisEndpoint, ISpecifyMessageHandlerOrdering
{
public void SpecifyOrder(Order order)
{
order.Specify<FIRST<YourHandler>>();
}
}
这篇关于NServiceBus:指定信息秩序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!