问题
I am trying to use Topshelf to create a Rebus endpoint that will run as a service. How should this be set up and are there any examples?
回答1:
You can take a look at the Rebus samples repository, where the integration service sample in particular shows what you're after.
As you can see in Program.cs it uses Topshelf to basically just hold on to a Windsor container, which it disposes when the application shuts down.
The Castle 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 shows how you can add handlers to the container.
It should be fairly easy to adapt the sample to use another container - just remember to dispose it when the application shuts down, thus giving Rebus a chance to finish messages currently being handled and stop its worker threads.
来源:https://stackoverflow.com/questions/27828099/how-to-configure-a-rebus-endpoint-to-run-as-a-service