0

我有一项服务需要在多台机器上运行,从单个队列中挑选作业,确保每个作业仅由单个服务承担。我还需要发布消息以供所有服务接收,例如重新加载触发器。

在没有太多黑客攻击的情况下,这可能在 nservicebus 中实现吗?

我已经证明发布模型和发送模型都对我有用,但是一旦我的客户需要处理这两种架构,它就会将它们全部视为发送架构,并且并非所有服务都接收发布方法。

这是我到目前为止的配置文件:

发布者(所有服务都需要接收这些消息),使用 Bus.Publish<...>(...):

  <MsmqTransportConfig InputQueue="ConfigQueue" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />

  <UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="" ForwardReceivedMessagesTo="">
<!-- Message publishers don't require message queues -->
<MessageEndpointMappings />  </UnicastBusConfig>

发件人(只有一项服务可以接收这些),使用 Bus.Send<...>(...):

  <MsmqTransportConfig InputQueue="BrokerQueue" ErrorQueue="error" numberOfWorkerThreads="1" MaxRetries="5" />

  <UnicastBusConfig DistributorControlAddress="" DistributorDataAddress="" ForwardReceivedMessagesTo="">
<MessageEndpointMappings>
  <add Messages="EventMessage, Messages" Endpoint="AgentQueue" />
</MessageEndpointMappings>  </UnicastBusConfig>

服务(每个都有相同的本地队列名称并订阅上面的发布者):

  <MsmqTransportConfig InputQueue="AgentQueue" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />

  <UnicastBusConfig>
<MessageEndpointMappings>
  <add Messages="NServiceBus.Messages.ReloadMessage, NServiceBus.Messages" Endpoint="ConfigQueue" />
</MessageEndpointMappings>  </UnicastBusConfig>
4

1 回答 1

1

不同机器之间的负载均衡是通过 NServiceBus 自带的 Distributor 来完成的。(远程事务读取在 MSMQ 上不稳定,不推荐)

因此,您发送的所有内容都会进入同一个输入队列,在您的情况下是 BrokerQueue。然后,您将配置分发器以馈送该队列。

可以在此处找到有关如何配置分发器的更多信息:

http://tech.groups.yahoo.com/group/nservicebus/message/2009

希望这可以帮助!

于 2009-12-21T12:52:23.373 回答