如何配置 Rebus 端点以作为服务运行

How to configure a Rebus endpoint to run as a service

我正在尝试使用 Topshelf 创建将作为服务运行的 Rebus 端点。应该如何设置,有没有例子?

您可以看一下 Rebus samples repository, where the integration service sample 特别显示您所追求的内容。

正如您在 Program.cs 中看到的那样,它使用 Topshelf 基本上只保留一个 Windsor 容器,它会在应用程序关闭时处理该容器。

温莎城堡 installer syntax causes the installers to be automatically picked up, where the RebusInstaller shows how you'd typically let Rebus inject itself into your container, and the HandlerInstaller 展示了如何向容器中添加处理程序。

调整示例以使用另一个容器应该相当容易 - 只需记住在应用程序关闭时处理它,从而让 Rebus 有机会完成当前正在处理的消息并停止其工作线程。