NServiceBus 侦听器丢失消息
我刚刚开始使用 nservice 总线,并试图让发布工作正常进行。我有一个听众似乎丢失了一些消息。 有趣的是
<MsmqTransportConfig
InputQueue="InformMessages"
ErrorQueue="error"
NumberOfWorkerThreads="5"
MaxRetries="5"
/>
,如果我将 NumberOfWorkerThreads 设置为 1,它会始终错过所有其他消息。对于较大的值,它似乎不太确定。在我的消息处理程序中
class MessageHandler : IMessageHandler<ICourseRegister>
{
public void Handle(ICourseRegister message)
{
Console.WriteLine("Message dun got gotted");
Console.WriteLine("Course name is: " + message.CourseName);
}
private IBus bus;
public IBus Bus
{
set { this.bus = value; }
}
}
,总线配置为“
var bus = NServiceBus.Configure.With()
.SpringBuilder()
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true)
.PurgeOnStartup(false)
.UnicastBus()
.ImpersonateSender(false)
.LoadMessageHandlers()
.CreateBus()
.Start();
是否有我需要做的事情”和处理程序的末尾,以便它可以释放准备接收下一条消息或我需要做的一些配置,以便有一个客户端队列如果处理程序繁忙,则保留消息。发送消息之间的时间似乎并不重要,可能是 20 秒,而侦听器仍然没有收到所有消息。
I am just starting to play with nservice bus and am trying to get publishing working. I have a listener which seems to be missing some messages. It is configured with
<MsmqTransportConfig
InputQueue="InformMessages"
ErrorQueue="error"
NumberOfWorkerThreads="5"
MaxRetries="5"
/>
Interestingly if I set NumberOfWorkerThreads to 1 it consistently misses every other message. For larger values it seems less determinate. In my message handler I have
class MessageHandler : IMessageHandler<ICourseRegister>
{
public void Handle(ICourseRegister message)
{
Console.WriteLine("Message dun got gotted");
Console.WriteLine("Course name is: " + message.CourseName);
}
private IBus bus;
public IBus Bus
{
set { this.bus = value; }
}
}
and the bus is configured with
var bus = NServiceBus.Configure.With()
.SpringBuilder()
.XmlSerializer()
.MsmqTransport()
.IsTransactional(true)
.PurgeOnStartup(false)
.UnicastBus()
.ImpersonateSender(false)
.LoadMessageHandlers()
.CreateBus()
.Start();
Is there something I need to do and the end of Handler such that it is freed ready to receive the next message or some configuration I need to do so that there is a client side queue to retain messages if the handler is busy. The time between sending messages doesn't seem to matter, it could be 20 seconds and the listener still doesn't get all the messages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看了你发来的解决方案后,我明白了问题所在。
您已为两个进程(发布者和订阅者)指定了相同的输入队列。结果,两个进程都在争夺(我认为)您打算只发送给订阅者的消息。
为每个进程提供自己的输入队列,一切都应该与世界正确:-)
After taking a look at the solution you sent over, I see what the problem is.
You've specified the same input queue for both processes - the publisher and the subscriber. As a result, you have both processes fighting over the messages which (I think) you intend to be going only to the subscriber.
Give each process its own input queue and everything should be right with the world :-)
如果您的工作方式与 pub/sub 示例类似,您可能会看到“多态订阅”。
在 pub/sub 示例中,发布者交替发布接口 IEvent 和具体类 EventMessage(继承 IEvent)。
如果订阅者订阅了具体类,则它将不会收到接口消息。对于所有类型的层次结构都是如此,如果您订阅了特定的类,并且发布者发布了其基类类型的消息,则该消息将不会被调度。
多态订阅则以相反的方式工作。如果您订阅基础类,则发布者发布的任何子类都会到达。
这与线程无关。
希望有帮助。
If you're working similar to the pub/sub sample, what you could be seeing is "polymorphic subscriptions".
In the pub/sub sample, the publisher alternately publishes an interface IEvent and a concrete class EventMessage (which inherits IEvent).
If a subscriber is subscribed to the concrete class, then it won't receive the interface messages. This is true for all kinds of hierarchies, if you subscribe to the specific class, and the publisher publishes a message of the type of its base class, the message won't be dispatched.
The polymorphic subscriptions works the other way around. If you subscribe to the base, any subclass that the publisher publishes will arrive.
This has nothing to do with threading.
Hope that helps.