如何向 NServiceBus Generic Host 添加服务依赖项
我有以下服务布局:
- 接口服务(从WCF请求、TCP请求、轮询等生成命令)
- 工作服务(使用接口服务生成的命令并发布事件)
- 事件处理程序服务(处理工作人员服务生成的事件)
我正在使用 MSMQ 订阅存储。
我当前的问题是,我必须在辅助服务启动之后启动事件处理程序服务。如果我相反地执行此操作,或者重新启动工作人员服务,事件处理程序服务将不会收到发布内容。
我的第一个想法是添加对事件处理程序服务的服务依赖。
我如何使用 NServiceBus 提供的通用主机来做到这一点?有更好的方法来解决问题吗?
I have the following services Layout:
- Interface Service (generates commands from WCF requests, TCP requests, Polling, etc.)
- Worker Service (consumes commands generated by interface service and publishes events)
- Event Handler Service (handles events generated by worker service)
I am using the MSMQ Subscription storage.
My current problem is that I have to start the event handler service after the worker service is started. If I do it in reverse, or restart the worker service publications won't be received by the event handler service.
My first idea is to add a service dependency on the event handler service.
How would I do this using the generic host provided by NServiceBus? Is there a better way to solve the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用 MSMQ 作为订阅存储,则使订阅队列具有事务性。
然后,即使重新启动后,来自事件处理程序服务的订阅消息仍将保留在工作服务订阅队列中。
关于启动顺序,无论工作服务是否启动,事件处理程序服务都会将订阅放入工作服务的输入队列中。所以启动顺序也不重要。
更新
实际上,这完全是不正确的,因为使队列具有事务性将为您提供跨服务器重新启动的持久性。
对于非事务性队列,您仍然应该获得与我上面描述的相同的行为。
If you are using MSMQ as subscription storage then make the subscription queue transactional.
Then the subscription messages from the event handler service will remain on the worker service subscription queue even after restarting.
Regarding start up order, the event handler service will put a subscription into the input queue of the worker service, whether or not the worker services is started. So the start up order is also unimportant.
UPDATE
Actually this is strictly untrue, because making the queues transactional will give you durability across server restarts.
You should still get the same behaviour I described above with non-transactional queues.
我建议使用数据库订阅选项。这将保留您的订阅。
I would recommend using the DB subscription option. This will keep your subscriptions around.