NServiceBus消息重播存档架构

时间:2011-03-12 00:12:33

标签: nservicebus archiving replay

我正在构建一个需要保存正在发送的消息副本的应用程序,以便我可以在以后重播所有消息。这是必要的,因为消息的处理在开发过程中会发生显着变化,但必须尽快捕获数据,因为它是实时观察数据。我似乎无法找到任何直接解决这个问题的内置功能,虽然我可以编写一个自定义工具来保存数据,这似乎与首先使用NServiceBus的目的相矛盾。我正在考虑的一些选择:

  1. 使用Target总线的ForwardReceivedMessagesTo功能创建存档队列,并构建一个简单的应用程序,该应用程序将此存档队列用作输入队列,以便在运行Replayer工具时将消息简单地转发到Target总线上。这确实清除了存档队列,要求首先使用mqbkup实用程序对其进行备份,但这可以作为重放过程的一部分自动执行。或者,使用两个交替的存档队列(一个接收新消息,一个用于重放)将解决此问题。

  2. 使用发布/订阅模型并让Archiver订阅目标队列,将消息放入存档队列。类似于上面的重播工具可以使用存档队列作为输入队列并将消息转发给目标。这也将清除存档队列,需要上述解决方案之一。

  3. MassTransit的人提到了一个名为BusDriver的东西,允许在队列之间复制,但我找不到更多关于它的信息。

  4. 我主要担心的是选择最不可能丢失数据的方法,因为一旦进行观察,它就永远不能在狭窄的时间窗口之外再次进行。这似乎应该是一个常见的问题,但我似乎无法找到一个简单的解决方案。建议?

    更新我决定使用带有记录的Target队列。我将让Archiver使用日志作为输入并将消息存储到数据库(可能只是基于文件),以及允许将消息从该数据库重放到目标队列。虽然可以编写一个将日志队列中的消息复制到目标队列的工具,但从实际角度来看,真正的问题是管理日志队列:它无法轻松备份(mqbkup降低了) MSMQ服务,这是不可接受的),并且在队列上非破坏性地运行需要我编写一个基于MSMQ的工具,而我宁愿坚持NServiceBus抽象级别。最终,MSMQ是一种传输而不是消息存储,因此需要对其进行处理。

2 个答案:

答案 0 :(得分:1)

第一种选择似乎可行。我想补充一点,NSB附带了一个名为ReturnToSourceQueue.exe的工具,它将为您重放消息。您可以打开日志来保留消息,但是由于它不会滚动,所以必须清理它。我们有NetApp,我们已经使用它的SnapMirror来备份队列数据,我确信那里有类似的东西。

答案 1 :(得分:1)

#3 BusDriver命令行参考:

BusDriver is a command-line utility used to administer queues, service bus instances and other things related to MassTransit.

Command-Line Reference

  busdriver.exe [verb] [-option:value] [--switch]

    help, --help        Displays help

    count               Counts the number of messages in the specified
                        queue

      -uri              The URI of the queue

    peek                Displays the body of messages in the queue without
                        removing the messages

      -uri              The URI of the queue
      -count            The number of messages to display

    move                Move messages from one queue to another

      -from             The URI of the source queue
      -to               The URI of the destination queue
      -count            The number of messages to move

    requeue             Requeue messages from one queue to another

      -uri              The URI of the queue
      -count            The number of messages to move

    save                Save messages from a queue to a set of files

      -uri              The URI of the source queue
      -file             The name of the file to write to (will have .1, .2
                        appended automatically for each message)
      -count            The number of messages to save
      --remove          If set, the messages will be removed from the queue

    load                Load messages from a set of files into a queue

      -uri              The URI of the destination queue
      -file             The name of the file to read from (will have .1, .2
                        appended automatically for each message)
      -count            The number of messages to load
      --remove          If set, the message file will be removed once the
                        message has been loaded

    trace               Request a trace of messages that have been received
                        by a service bus

      -uri              The URI of the control bus for the service bus
                        instance
      -count            The number of messages to request

        status          Request a status probe of the bus at the endpoint

          -uri          The URI of the control bus for the service bus instance

    exit, quit          Exit the interactive console (run without arguments
                        to start the interactive console)

Examples:

    count -uri:msmq://localhost/mt_server
        Returns the number of messages that are present in the local
        MSMQ private queue named "mt_server"

    peek -uri:msmq://localhost/mt_client
        Displays the body of the first message present in the local
        MSMQ private queue named "mt_client"

    trace -uri:msmq://localhost/mt_subscriptions
        Requests and displays a trace of the last 100 messages received
        by the mt_subscriptions (the default queue name used by the
        subscription service, which is part of the RuntimeServices)

    move -from:msmq://localhost/mt_server_error -to:msmq://localhost/mt_server
        Moves one message from the mt_server_error queue to the mt_server
        queue (typically done to reprocess a message that was previously
        moved to the error queue due to a processing error, etc.)