NServiceBus 订阅不起作用

发布于 2024-12-28 21:32:49 字数 3010 浏览 1 评论 0原文

我正在尝试设置一个 NServiceBus PubSub 示例,该示例托管在一组 Windows 服务中。

我已经配置了我的发布者,并且可以看到它调用我的总线发布方法。我还配置了一个订阅者来监听我发送的消息。然而,实际的订阅过程似乎没有正常工作,因为我看不到一条日志消息,表明订阅者已被订阅(就像我在 PubSub 示例中所做的那样)。

我只是想知道您自己托管服务时是否需要某种魔法才能使这项工作正常进行。

下面是我的配置

发布者

App.Config

 <configSections>
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
  </configSections>
  <!-- 1. In order to configure remote endpoints use the format: "queue@machine" 
       2. Input queue must be on the same machine as the process feeding off of it.
       3. Error queue can (and often should) be on a different machine.
       4. The community edition doesn't support more than one worker thread.
  -->

  <MsmqTransportConfig InputQueue="publisher.input" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />
  <UnicastBusConfig>
    <MessageEndpointMappings></MessageEndpointMappings>
  </UnicastBusConfig>

总线设置:

var bus = Configure.With()
            .Log4Net()
            .NinjectBuilder()
            .XmlSerializer()
            .MsmqSubscriptionStorage()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(false)
            .UnicastBus()
                .ImpersonateSender(false)
            .CreateBus()
            .Start();

订阅者

App.Config

<configSections>
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
  </configSections>
  <!-- 1. In order to configure remote endpoints use the format: "queue@machine" 
       2. Input queue must be on the same machine as the process feeding off of it.
       3. Error queue can (and often should) be on a different machine.
       4. The community edition doesn't support more than one worker thread.
  -->

  <MsmqTransportConfig
    InputQueue="subscriber.input"
    ErrorQueue="error"
    NumberOfWorkerThreads="1"
    MaxRetries="5"
  />

  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="MyEventNamespace" Endpoint="publisher.input" />
    </MessageEndpointMappings>
  </UnicastBusConfig>

总线设置:

        var bus = Configure.With()
            .Log4Net()
            .NinjectBuilder()
            .XmlSerializer()
            .MsmqSubscriptionStorage()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(false)
            .UnicastBus()
                .ImpersonateSender(false)
            .CreateBus()
            .Start();

有什么我遗漏或做的很愚蠢的事情吗?

干杯

Im trying to setup an NServiceBus PubSub example which is hosted inside a set of windows services.

I have configured my publisher and can see it calling my buses publish method. Ive also configured a subscriber to listen to the messages i am sending. It appears however that the actual subscription process hasnt worked properly as i cant see a log message saying the subscriber has been subscribed (as i do in the PubSub sample).

Im just wondering if you need some kind of magic to make this work when hosting the service yourself.

below is my config

Publisher

App.Config

 <configSections>
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
  </configSections>
  <!-- 1. In order to configure remote endpoints use the format: "queue@machine" 
       2. Input queue must be on the same machine as the process feeding off of it.
       3. Error queue can (and often should) be on a different machine.
       4. The community edition doesn't support more than one worker thread.
  -->

  <MsmqTransportConfig InputQueue="publisher.input" ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />
  <UnicastBusConfig>
    <MessageEndpointMappings></MessageEndpointMappings>
  </UnicastBusConfig>

Bus Setup:

var bus = Configure.With()
            .Log4Net()
            .NinjectBuilder()
            .XmlSerializer()
            .MsmqSubscriptionStorage()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(false)
            .UnicastBus()
                .ImpersonateSender(false)
            .CreateBus()
            .Start();

Subscriber

App.Config

<configSections>
    <section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
    <section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
  </configSections>
  <!-- 1. In order to configure remote endpoints use the format: "queue@machine" 
       2. Input queue must be on the same machine as the process feeding off of it.
       3. Error queue can (and often should) be on a different machine.
       4. The community edition doesn't support more than one worker thread.
  -->

  <MsmqTransportConfig
    InputQueue="subscriber.input"
    ErrorQueue="error"
    NumberOfWorkerThreads="1"
    MaxRetries="5"
  />

  <UnicastBusConfig>
    <MessageEndpointMappings>
      <add Messages="MyEventNamespace" Endpoint="publisher.input" />
    </MessageEndpointMappings>
  </UnicastBusConfig>

Bus Setup:

        var bus = Configure.With()
            .Log4Net()
            .NinjectBuilder()
            .XmlSerializer()
            .MsmqSubscriptionStorage()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(false)
            .UnicastBus()
                .ImpersonateSender(false)
            .CreateBus()
            .Start();

Is there anything I'm missing or doing stupidly?

Cheers

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

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

发布评论

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

评论(3

余厌 2025-01-04 21:32:49

主要问题是您在订阅者中的 .UnicastBus() 之后没有调用 .LoadMessageHandlers() 。因此,它不知道您有一个配置为来自publisher.input 的事件处理程序,因此不会订阅。

另一件事是,您不需要包含订阅者的 .MsmqSubscriptionStorage() 。

The main problem is that you haven't called .LoadMessageHandlers() after .UnicastBus() in your subscriber. As a result, it doesn't know that you have a handler for the event that is configured to come from publisher.input and, as a result, doesn't subscribe.

One other thing, you don't need to include the .MsmqSubscriptionStorage() for the subscriber.

路还长,别太狂 2025-01-04 21:32:49

在订阅者中,您可以调用 Bus.Subscribe() 并显式设置它。

In the subscriber you can make a call to Bus.Subscribe() and set it up explicitly.

雾里花 2025-01-04 21:32:49

对于使用“不显眼模式”的任何人,您还应该确保定义了消息约定。

我在某个地方看到了一个示例,该示例已将其添加到消息处理程序的项目中:

class MessageConventions : IWantToRunBeforeConfiguration { 
   public void Init() {
      Configure.Instance.DefiningMessagesAs(t => t.Namespace != null &&  
            t.Namespace.StartsWith("Your.Messages.Namespace.Here"));
   }
}

这对我有用。

示例代码此处 包含类似的内容。

For anyone using "Unobtrusive Mode" you should also ensure you have a message convention defined.

Somewhere I saw an example that had added this to the message handler's project:

class MessageConventions : IWantToRunBeforeConfiguration { 
   public void Init() {
      Configure.Instance.DefiningMessagesAs(t => t.Namespace != null &&  
            t.Namespace.StartsWith("Your.Messages.Namespace.Here"));
   }
}

which worked for me.

The example code here contains something similar.

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