使用 TopShelf 创建简单的 MQ windows 服务
我正在使用 Topshelf 创建一个简单的 MQ 读取服务。由于可用的文档很少 - 我遇到了一些可能简单的问题,我希望在这里得到解答:
1)一般来说 - 获得我的服务实例的实际服务库实例会非常好,因为有很多方法可以我想访问。我怎样才能做到这一点?
2)当OnStop被调用时,我想刷新MQ并快速处理剩余的消息。但是,在 OnClose 中访问 MQ 会引发 MQ 访问异常 - 这是设计使然还是?
3) 我已在配置器中指定了 OnPause 和 OnContinue 重载。但是,由于未设置AllowPauseAndContinue 标志,因此服务未启用暂停/继续。最好的方法是什么?
var retVal = HostFactory.New( x =>
{
x.Service<ASForwardMessageService>( s =>
{
s.SetServiceName( s_ServiceName );
s.ConstructUsing( name => CreateService() );
s.WhenStarted( tc => tc.OnStart() );
s.WhenStopped( tc => tc.OnStop() );
s.WhenPaused( tc => tc.OnPause() );
s.WhenContinued( tc => tc.OnContinue() );
} );
x.RunAsLocalSystem();
x.DependsOnMsmq();
x.StartAutomatically();
x.SetDescription( s_Description );
x.SetDisplayName( s_DisplayName );
x.SetServiceName( s_ServiceName );
} );
顺便说一句 - 是否有任何适用于 Topshelf 项目的文档 - 如果有的话那就太好了。
感谢您提供一个很棒的图书馆!
I am using Topshelf for creating a simple MQ reading service. Since the documentation available is sparse - I have run into some probably simple questions that I hope get answered here:
1) Generally - it would be very nice to get the actual servicebase instance of my service instance, since there is a bunch of methods that I would like to access. How can I do that?
2) When OnStop is called, I would like to flush the MQ and quickly process the remaining messages. However, accessing the MQ in the OnClose raises an MQ access exception - is this by design, or?
3) I have specified the OnPause and OnContinue overloads in the configurator. However - the service is not pause/continue enabled, since the AllowPauseAndContinue flag is not set. What is the best way to do that?
var retVal = HostFactory.New( x =>
{
x.Service<ASForwardMessageService>( s =>
{
s.SetServiceName( s_ServiceName );
s.ConstructUsing( name => CreateService() );
s.WhenStarted( tc => tc.OnStart() );
s.WhenStopped( tc => tc.OnStop() );
s.WhenPaused( tc => tc.OnPause() );
s.WhenContinued( tc => tc.OnContinue() );
} );
x.RunAsLocalSystem();
x.DependsOnMsmq();
x.StartAutomatically();
x.SetDescription( s_Description );
x.SetDisplayName( s_DisplayName );
x.SetServiceName( s_ServiceName );
} );
By the way - is there any documentation available for the Topshelf project - would be very nice to have around.
Thanks for a great library!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
https://github.com/Topshelf/Topshelf/wiki 获取文档,还有 http://topshelf-project.com/ 但我们实际上没有太多文档。对于我们的邮件列表来说,这可能也是一个更好的讨论。
我们不会公开这一点,尽管我想我们可以通过新的安装前和安装后事件(http://legomaster.net/2011/02/announcing-topshelf-2-2/)来实现。总的想法是,您需要设置的任何内容都将通过我们的配置 API 公开。您希望获得哪些您认为现在没有的关注项目?
您看到什么异常?据我所知,Topshelf 的设计中没有任何内容会导致此问题。
CanPauseAndContinue
未设置;在 github 上的问题跟踪器中删除一个问题,我认为这是可以解决的问题。https://github.com/Topshelf/Topshelf/wiki for documentation, there's also http://topshelf-project.com/ but we don't really have much in terms of docs up there. This might be a better discussion for our mailing list as well.
We don't expose that, though I guess it's possible we could via the new pre- and post- install events (http://legomaster.net/2011/02/announcing-topshelf-2-2/). The general idea is that anything you would need to set would be exposed via our configuration API though. What attention items do you want access to you feel that you don't have now?
What exception are you seeing? There isn't anything I'm aware of in the design of Topshelf which should be causing this issue.
CanPauseAndContinue
isn't set; drop an issue in our issue tracker on github and I think that's something that can be resolved.