简体   繁体   English

NServiceBus中的并发句柄调用

[英]Concurrent Handle calls in NServiceBus

I would like my IHandleMessages<X>.Handle(X x) methods to be called concurrently by NSB. 我希望我的IHandleMessages <X> .Handle(X x)方法可以由NSB同时调用。 Even when configuring the default host AsA_Client - which turns off transactions - and providing two or more threads (NumberOfWorkerThreads="3" in App.Config), the following handler is called twice sequentially when there are two messages on the queue: 即使配置默认主机AsA_Client(关闭事务)并提供两个或多个线程(App.Config中的NumberOfWorkerThreads =“3”),当队列中有两条消息时,依次调用以下处理程序两次:

public void Handle(EventMessage message)
{
    Logger.Info(string.Format("Subscriber 1 received EventMessage with Id {0}.", message.EventId));
    Logger.Info(string.Format("Message time: {0}.", message.Time));
    Logger.Info(string.Format("Message duration: {0}.", message.Duration));
    Thread.Sleep(10000);
}

This is merely a modified version of the PubSub demo that is supplied with NSB. 这仅仅是NSB提供的PubSub演示的修改版本。 No matter what settings I provide - I've also tried tweaking the IsolationLevel, to no avail - this handler blocks concurrent calls. 无论我提供什么设置 - 我也试过调整IsolationLevel,但无济于事 - 这个处理程序会阻止并发调用。

In practice, this is not desirable for one specific set of handlers that we are writing. 实际上,对于我们正在编写的一组特定处理程序来说,这是不可取的。 The desired behavior would be - at minimum - to let concurrent threads into the Handle method and we would manually mediate access to state with software locks. 期望的行为 - 至少 - 让并发线程进入Handle方法,我们将手动调解对软件锁的状态访问。

Is this not possible or am I missing a trick? 这是不可能的还是我错过了一招?

The most likely cause is that you're using the free Express Edition of NServiceBus which is limited to a single thread. 最可能的原因是您正在使用NServiceBus的免费Express Edition,它仅限于一个线程。 The commercially available Standard Edition allows you to run multiple threads. 商用标准版允许您运行多个线程。

NOTE : NServiceBus now performs at full speed in the free trial - no more performance throttling. 注意 :NServiceBus现在在免费试用中全速运行 - 不再进行性能限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM