Something making NServiceBus lose messages

独自空忆成欢 提交于 2019-12-04 15:57:51
Vaccano

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

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)

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

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).

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

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. Expressly state what your handler(s) should be:

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

  2. 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.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!