NServicebus 添加到旧版 Windows 服务

发布于 2024-09-16 15:09:19 字数 1129 浏览 2 评论 0原文

我有一个简单的类,它为旧版 Windows 服务设置 NserviceBus。当服务启动时会调用此配置。当我将应用程序作为控制台应用程序运行时,会拾取 App.config 中的配置,但是当我将应用程序作为 Windows 服务运行时,不会拾取 App.config 配置。有什么方法可以指定应用程序配置位置吗? (正如我对 log4net.config 所做的那样)。

namespace MossSapUploadInterface
{
    public static class BootStrapper
    {
        public static void Init()
        {
            var config = AppDomain.CurrentDomain.BaseDirectory + "log4net.config";
            XmlConfigurator.Configure(new FileInfo(config));
            var log = LogManager.GetLogger(typeof(BootStrapper));
            ObjectFactory.Initialize(x => x.AddRegistry<MessageServiceRegistry>());
            ObjectFactory.Configure(x => x.For<ILog>().TheDefault.Is.Object(log));


            var bus = Configure.With()
                .StructureMapBuilder(ObjectFactory.Container)
                .MsmqTransport()
                .IsTransactional(true)
                .UnicastBus()
                .ImpersonateSender(false)
                .XmlSerializer()
                .CreateBus()
                .Start();
            SetLoggingLibrary.Log4Net();
        }
    }
}

I have a simple class which sets up NserviceBus for a legacy windows service. This configuration is called when the service starts up. When I run the application as a console app the configuration in the App.config is picked up, however when running the application as a windows service the App.config configuration isn't picked up. Is there any way I can specify the app config location? (as I have done with the log4net.config).

namespace MossSapUploadInterface
{
    public static class BootStrapper
    {
        public static void Init()
        {
            var config = AppDomain.CurrentDomain.BaseDirectory + "log4net.config";
            XmlConfigurator.Configure(new FileInfo(config));
            var log = LogManager.GetLogger(typeof(BootStrapper));
            ObjectFactory.Initialize(x => x.AddRegistry<MessageServiceRegistry>());
            ObjectFactory.Configure(x => x.For<ILog>().TheDefault.Is.Object(log));


            var bus = Configure.With()
                .StructureMapBuilder(ObjectFactory.Container)
                .MsmqTransport()
                .IsTransactional(true)
                .UnicastBus()
                .ImpersonateSender(false)
                .XmlSerializer()
                .CreateBus()
                .Start();
            SetLoggingLibrary.Log4Net();
        }
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半仙 2024-09-23 15:09:19

解决此问题的一种方法是实现您自己的自定义配置源:

http ://sourceforge.net/apps/mediawiki/nservicebus/index.php?title=Overriding_Configuration

One way to solve this would be to implement your own custom config source:

http://sourceforge.net/apps/mediawiki/nservicebus/index.php?title=Overriding_Configuration

与往事干杯 2024-09-23 15:09:19

我可以确认我错了。配置是从 App.config 中获取的。通过以下日志验证:

var destinationQueue = Configure.ConfigurationSource.GetConfiguration<UnicastBusConfig>().MessageEndpointMappings[0].Endpoint;
log.Info("Endpoint Mapped to: " + destinationQueue);

似乎结构映射配置确实在当前域目录中查找配置,而不是我对默认服务目录的第一个想法:“c:\Windows\system32...”

I can confirm I was wrong. The configuration is picked up from the App.config. As verified by the following log:

var destinationQueue = Configure.ConfigurationSource.GetConfiguration<UnicastBusConfig>().MessageEndpointMappings[0].Endpoint;
log.Info("Endpoint Mapped to: " + destinationQueue);

Seems the structuremap config does look in current domain directory for the configuration, as opposed to my first thoughts of the default services directory: "c:\Windows\system32..."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文