NServiceBus 订阅不起作用
我正在尝试设置一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
主要问题是您在订阅者中的 .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.
在订阅者中,您可以调用 Bus.Subscribe() 并显式设置它。
In the subscriber you can make a call to Bus.Subscribe() and set it up explicitly.
对于使用“不显眼模式”的任何人,您还应该确保定义了消息约定。
我在某个地方看到了一个示例,该示例已将其添加到消息处理程序的项目中:
这对我有用。
示例代码此处 包含类似的内容。
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:
which worked for me.
The example code here contains something similar.