使NServiceBus丢失消息的东西 [英] Something making NServiceBus lose messages

查看:176
本文介绍了使NServiceBus丢失消息的东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NServiceBus配置,它在开发人员机器和我的开发环境中运行良好。

I have an NServiceBus configuration that is working great on developers machines and in my Development Environment.

然而,当我将它移动到我的测试环境时,我的消息才刚刚开始被抛出。

However, when I move it to my Test Environment my messages just start getting tossed.

这是系统:


  1. 应用程序获取TCP来自大型机系统的消息并将其发送到MSMQ(称之为 FromMainframe )。

  2. IIS中托管的应用程序具有句柄 该MSMQ的方法并处理来自大型机的消息。

在我的测试环境中,第二步只发生了一半。消息从MSMQ弹出,但我的应用程序没有处理。

In my Test Environment, step two only half way happens. The message is popped off the MSMQ, but not processed by my application.

实际上我的数据 LOST ! NServiceBus将它们从队列中删除但我永远不会处理它们。它们甚至不在错误队列中!

Effectively my data is LOST! NServiceBus removes them from the Queue but I never get to process them. They are not even in the error queue!

这些是我试过的东西,试图弄清楚发生了什么:

These are the things I have tried in an attempt to figure out what is happening:


  1. 检查配置文件

  2. 将远程调试器附加到流程以查看句柄方法正在执行

    • 从不调用句柄方法(但是当我附加到开发环境我的 Handle 方法中的断点被击中并且一切正常运行。

  1. Check the Config files
  2. Attach a remote debugger to the process to see what the Handle method is doing
    • The Handle method is never called (but when I attach to the Development Environment my breakpoint in my Handle method is hit and it all works flawlessly).

  • 错误队列保持空(我希望它会填满,然后我的数据不会丢失)。


  • 我关闭了我的IIS网站,并且 FromMainframe 队列中的消息开始备份。

  • 当我重新打开时,消息消失得相当快(但仍然不是一次全部消失)。它们消失的速度太快,以至于我的 Handle 方法处理它们。

  • I Turned off my IIS website and the messages in the FromMainframe queue start to backup.
  • When I turn it back on, the messages disappear fairly fast (but still not all at once). The speed that they disappear is too fast for them to be processed by my Handle method.

  • I跑了,重新启动,再次运行它以获得好的措施!


  • 我不认为可以使用另一台计算机的MSMQ作为你的输入队列,但检查没有坏处。


  • 当我在IIS之外托管(使用NServiceBus.Host.exe)时,一切正常。所以它必须是一个IIS的东西吗?


推荐答案

所以我对发生的事情了解得太多了。

So I know enough about what happened to throw out an "Answer".

当我设置我的NServiceBus自托管时,我有一个加载消息处理程序的调用。

When I setup my NServiceBus self hosting I had a call that loaded the message handlers.

NServiceBus.Configure.With().LoadMessageHandlers()

(有)更多配置,但我为了简洁起见省略了它们。

(There are more configurations, but I omitted them for brevity)

当你调用它时,NServiceBus扫描assmeblies一个实现 IHandleMessages< T>的类了。

When you call this, NServiceBus scans the assmeblies for a class that implements IHandleMessages<T>.

所以,不知何故,在我的测试环境机器上,调用IHandleMessages的类的目录的ServiceBus扫描未能找到我的class(即使程序集绝对存在)。

So, somehow, on my Test Environment Machine, the ServiceBus scan of the directory for a class that calls IHandleMessages was failing to find my class (even though the assembly was absolutely there).

如果NServiceBus找不到处理的东西一条消息 THROW IT AWAY !!!

Turns out that if NServiceBus does not find something that handles a message it will THROW IT AWAY!!!

在我看来,这是一个完整的设计错误。 NServiceBus的整个想法是不会丢失你的数据,但在这种情况下它就是这样!

This is a total design bug in my opinion. The whole idea of NServiceBus is to not lose your data, but in this case it does just that!

现在,一旦你知道这个陷阱,有几种方法可以解决它。

Now, once you know about this pitfall, there are several ways around it.


  1. 明确说明您的处理程序应该是什么:

  1. Expressly state what your handler(s) should be:

NServiceBus.Configure.With()。LoadMessageHandlers< First< MyMessageType>>()

更进一步的保护是添加另一个处理Everything的处理程序。 IMessage 是所有消息有效负载的基础,因此如果您在其上放置一个处理程序,它将拾取所有内容。

如果将IMessage设置为处理完消息之后处理,然后它将处理NServiceBus无法找到的所有内容处理程序。如果你在 Handle 方法中抛出异常会导致NServiceBus将消息移动到错误队列。 (我认为应该是默认行为。)

Even further protection is to add another handler that will handle "Everything else". IMessage is the base for all message payloads, so if you put a handler on it, it will pickup everything.
If you set IMessage to handle after your messages get handled, then it will handle everything that NServiceBus can't find a handler for. If you throw and exception in that Handle method that will cause NServiceBus to to move the message to the error queue. (What I think should be the default behavior.)

这篇关于使NServiceBus丢失消息的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆