NServiceBus:如何让订阅者在不使用通用主机的情况下开始处理混乱?

发布于 2024-10-05 15:32:30 字数 1271 浏览 2 评论 0原文

我正在修改 PubSub 示例,并一直在尝试 NServiceBus 的配置。目前,我的 EndpointConfig.cs 文件具有如下配置:

Configure.With(new[] { typeof(IEvent), typeof(NServiceBus.Unicast.Transport.CompletionMessage) })
            .CustomConfigurationSource(new UserConfigurationSource()
               .Register(() => new MsmqTransportConfig { InputQueue = "Subscriber2InputQueue", ErrorQueue = "error", NumberOfWorkerThreads = 1, MaxRetries = 5 }))
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport()
            .IsTransactional(true);

现在我想将其更改为没有通用主机的控制台应用程序。以下是我所做的更改:

  1. 将项目输出更改为控制台应用程序
  2. 将启动设置更改为不调用通用主机
  3. 将上面的配置移至 Main 方法,如下所示:

    Configure.With(new[] { typeof(IEvent), typeof(NServiceBus.Unicast.Transport.CompletionMessage) })
                .CustomConfigurationSource(new UserConfigurationSource()
                   .Register(() => new MsmqTransportConfig { InputQueue = "Subscriber2InputQueue", ErrorQueue = "error", NumberOfWorkerThreads = 1, MaxRetries = 5 }))
                .DefaultBuilder()
                .XmlSerializer()
                .MsmqTransport()
                .IsTransactional(true);
    
    
    
     Console.ReadLine();
    

我还应该做其他事情来“启动”订阅者来读取消息吗?

I am modifying the PubSub sample, and have been playing around with the configuration of NServiceBus. Currently, my EndpointConfig.cs file has configuration like this:

Configure.With(new[] { typeof(IEvent), typeof(NServiceBus.Unicast.Transport.CompletionMessage) })
            .CustomConfigurationSource(new UserConfigurationSource()
               .Register(() => new MsmqTransportConfig { InputQueue = "Subscriber2InputQueue", ErrorQueue = "error", NumberOfWorkerThreads = 1, MaxRetries = 5 }))
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport()
            .IsTransactional(true);

Now I want to change it to just be a console app without the generic host. Here's what I changed:

  1. Changed the project output to be Console app
  2. Changed the startup settings to not invoke the generic host
  3. Moved the configuration above to the Main method like this:

            Configure.With(new[] { typeof(IEvent), typeof(NServiceBus.Unicast.Transport.CompletionMessage) })
                .CustomConfigurationSource(new UserConfigurationSource()
                   .Register(() => new MsmqTransportConfig { InputQueue = "Subscriber2InputQueue", ErrorQueue = "error", NumberOfWorkerThreads = 1, MaxRetries = 5 }))
                .DefaultBuilder()
                .XmlSerializer()
                .MsmqTransport()
                .IsTransactional(true);
    
    
    
        Console.ReadLine();
    

Is there something else I should be doing to "startup" the subscriber to read messages?

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

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

发布评论

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

评论(2

忘年祭陌 2024-10-12 15:32:30

查看异步页面示例,了解如何自行托管 NServiceBus(就像在 IIS 中一样)。您缺少 .UnicastBus().LoadMessageHandlers().Start()。

Look at the Async Pages sample to see how to self-host NServiceBus (like in IIS). You're missing .UnicastBus().LoadMessageHandlers().Start().

何以畏孤独 2024-10-12 15:32:30

仅供参考,我的配置看起来像这样,

_Bus = NServiceBus.Configure.With()
              .DefaultBuilder()
              .Log4Net(new MyLogAppender())
              .XmlSerializer()
              .MsmqTransport()
                  .IsTransactional(false)
                  .PurgeOnStartup(true)
              .UnicastBus()
                  .ImpersonateSender(false)
                  .DoNotAutoSubscribe()
                  .LoadMessageHandlers()
              .CreateBus()
              .Start();

FYI my config looks something like,

_Bus = NServiceBus.Configure.With()
              .DefaultBuilder()
              .Log4Net(new MyLogAppender())
              .XmlSerializer()
              .MsmqTransport()
                  .IsTransactional(false)
                  .PurgeOnStartup(true)
              .UnicastBus()
                  .ImpersonateSender(false)
                  .DoNotAutoSubscribe()
                  .LoadMessageHandlers()
              .CreateBus()
              .Start();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文