如何订阅消息?自动/手动订阅如何工作?
我对发布/订阅的概念没有任何疑问,但我无法理解(自动)配置。
场景
- 我有一个前端服务 (F1),它执行命令消息 (M1) 的发送。
- 该命令消息由后端(B1)接收。 B1 进行一些处理,然后对通知消息 M2 进行 PUBLISH。
- 两个服务(F1 和 F2)应该接收此通知消息并执行其处理/任务。
[F1]=(M1)=> [B1]=(M2)=> [F1 和F2]
F1和F2如何订阅B1发布/广播的通知消息M2?
我在 .config 文件或示例代码中找不到实际配置,并且在 NServiceBus 网络广播上找不到有关此内容的文档。
有 IBus.Subscribe
但我看不到如何订阅某个实例。我希望我需要提供一个队列来发送订阅消息,以便我返回可以接收发布/公告。
简而言之
B1 对 M2 执行 PUBLISH。
- F1和F2如何订阅这条消息?
- 不使用自动订阅时如何工作?那么从代码或配置?
I have no trouble with the concept of publish/subscribe but I cannot get my head around the (auto)configuration.
Scenario
- I have a front-end service (F1) which does a SEND of a command message (M1).
- This command message is received by a back-end (B1). B1 does some processing and then does a PUBLISH of notification message M2.
- Two services (F1 and F2) should receive a this notification message and do their processing/tasks.
[F1] =(M1)=> [B1] =(M2)=> [F1 & F2]
How do F1 and F2 subscribe to notification message M2 which is published/broadcasted by B1?
I cannot find actual configuration in either .config files or code in the samples and I cannot find documentation about this on the NServiceBus webcast.
There is IBus.Subscribe<T>
but I cannot see how to subscribe a certain instance. I would expect that I need to supply a queue to which to send the subscribe message to so that I return can receive publishes/announcements.
In short
In short B1 does a PUBLISH of M2.
- How can F1 and F2 subscribe to this this message?
- How does it work when auto subscribe is not used? So from code or config?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您不自动订阅时,您必须在代码中显式地订阅自己。首先在 EndpointConfig 类上指定 IWantCustomInitialization 接口。然后,您告诉 NSB 不要自动订阅:
然后在您的订阅者端点中,实现 IWantToRunAtStartup 接口。您可以在那里订阅特定消息,例如:
When you do not auto-subscribe, you have to explicitly subscribe yourself in code. Start by specifying the IWantCustomInitialization interface on your EndpointConfig class. Then you tell NSB to not auto-subscribe:
Then within your subscriber endpoint, implement the IWantToRunAtStartup interface. There you can subscribe to specific messages, for example:
在 F1 和 F2 的配置文件中,在
UnicastBusConfig
部分的MessageEndpointMappings
下添加以下条目:然后,您还需要在 F1 和 F2 中为 M2 有一个消息处理程序。当总线看到这一点时,它会自动将订阅消息发送到B1的队列,接收端的总线将存储M2感兴趣的F1和F2的队列名称。
您的场景可能不需要
.DoNotAutoSubscribe()
位。In the config files of F1 and F2, in the
UnicastBusConfig
section, under theMessageEndpointMappings
the following entry:Then you also need to have a message handler in F1 and F2 for M2. When the bus sees this, it will automatically send the subscription message to the queue of B1, where the bus on the receiving side will store the names of the queues of F1 and F2 as interested in M2.
You probably don't need the
.DoNotAutoSubscribe()
bit for your scenario.