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

NServiceBus:如何让订阅者在不使用通用主机的情况下开始处理混乱?,nservicebus,Nservicebus,我正在修改PubSub示例,并一直在玩弄NServiceBus的配置。当前,我的EndpointConfig.cs文件具有如下配置: Configure.With(new[] { typeof(IEvent), typeof(NServiceBus.Unicast.Transport.CompletionMessage) }) .CustomConfigurationSource(new UserConfigurationSource() .

我正在修改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);
        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();
现在我想把它改成一个没有普通主机的控制台应用程序。以下是我所改变的:

  • 将项目输出更改为Console app
  • 已将启动设置更改为不调用通用主机
  • 将上面的配置移动到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);
    
            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();
    

  • 我还应该做些什么来“启动”订阅服务器以读取消息?

    查看Async Pages示例,了解如何自托管NServiceBus(如在IIS中)。您缺少.UnicastBus().LoadMessageHandlers().Start()。

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


    我假设您希望在LoadMessageHandler和Start之间有“.CreateBus()”?我试过了,但是队列中的消息没有被处理。我发现了问题。我已经尝试将“.UnicastBus().LoadMessageHandlers().CreateBus().Start()”添加到我的配置中,但正如您在“Configure.With(…)”部分中看到的,我引用了消息类型(IEEvent),但没有引用处理程序(EventMessageHandler)。