0

我没有仅使用 MQMessaging 的 HTTP 功能,因此不需要设置我的应用程序主机和侦听端口(此时)。我确实想要所有的管道,尽管默认情况下,即 IoC 等。

这可能吗?仅供参考,我现在正在使用 Topshelf 引导服务,它似乎工作正常,我只是不需要监听 HTTP 请求。

谢谢你,斯蒂芬

public class Program
{
    public static void Main()
    {
        HostFactory.Run(x =>                                 
        {
            x.Service<AppHost>(s =>                        
            {
                s.ConstructUsing(name => new AppHost());    
                s.WhenStarted(ah =>
                {
                    ah.Init();
                    ah.Start("http://*:8088/");
                    "Lead message processor listening at http://localhost:8088 ".Print();
                });              
                s.WhenStopped(ah => ah.Stop());              
            });
            x.RunAsLocalSystem();

            x.SetDescription("Processes all messages for the Leads application.");
            x.SetDisplayName("Leads Message Processor");
            x.SetServiceName("LOLeadsProcessor");                      
        });
    }
}

public class AppHost : AppSelfHostBase
{
    public AppHost()
        : base("LO.Leads.Processor", typeof(HelloService).Assembly)
    {
        // Logging
        LogManager.LogFactory = new NLogFactory();
    }

    public override void Configure(Container container)
    {

        //RabbitMQ
        container.Register<IMessageService>(c => new RabbitMqServer("cdev-9010.example.com", "test", "test")
        {
            AutoReconnect = true,
            DisablePriorityQueues = true,

        }); 
        RabbitMqServer mqServer = (RabbitMqServer)container.Resolve<IMessageService>();


        mqServer.RegisterHandler<HelloIntro>(m =>
        {
            return new HelloIntroResponse { Result = "Hello, {0}!".Fmt(m.GetBody().Name) };
        });

        mqServer.Start();

    }
}
4

1 回答 1

2

在 Windows 服务中托管 ServiceStack 与任何其他 .NET 应用程序没有什么特别之处,这最终是一个偏好问题。以下是 Windows 服务中的几个现有的 ServiceStack 应用程序示例(即没有 TopShelf):

自托管AppSelfHostBase通常是 Windows 服务将继承的,但如果您不需要支持 HTTP 请求,您可以只继承BasicAppHost或通用ServiceStackHost(所有 ServiceStack 主机都继承)。

于 2014-10-21T22:20:04.070 回答