NServiceBus 在订阅者订阅时发送信息 [英] NServiceBus sending information when a subscriber subscribes
问题描述
我刚刚开始使用 NServiceBus,并且已经启动并运行了一个非常基本的实现 - 很像 PubSub 示例应用程序.
I'm just getting started with NServiceBus and I've got a very basic implementation up and running - much like the PubSub sample application.
我想做的是在订阅者订阅时发送一些信息.
What I want to do is to send some information when a subscriber subscribes.
例如,假设我有一个包含分类产品的数据库.我的发布者将每 N 秒检查一次数据库,并在新产品添加到数据库时发送消息.
For example, lets say I have a database with products that are categorized. My publisher will check the database every N seconds and will send messages when a new product is added to the database.
但每个订阅者只对特定类别感兴趣,我想在他们订阅时发送该类别,以便发布者知道检查数据库中是否有该类别中的新产品.
But each subscriber is only interested in a particular category and I want to send that category when they subscribe so that the publisher knows the check the database for new products in that category.
类别是动态的,因此我无法为不同的类别创建不同的消息.因此,出于这个原因,我假设所有订阅者都必须订阅相同的已发布 IMessage
.
The categories are dynamic, so I can't create different messages for the different categories. So for that reason I assume that all the subscribers have to subscribe to the same published IMessage
.
注意:我也希望使用此信息来过滤 NServiceBus 发送给订阅者的消息,但我想我会 将其作为一个单独的问题发布.
推荐答案
您可以实现 IAuthorizeSubscriptions 接口,以便在订阅者请求订阅时在发布者处获得回调.如果您想在订阅请求中包含一些额外的元数据,您需要使用 Bus.OutgoingHeaders - 然后您可以在发布者处查看该信息并决定如何处理它.
You can implement the IAuthorizeSubscriptions interface to get a callback at the publisher when a subscriber requests to subscribe. If you wanted to include some additional meta-data in the subscription request, you'll need to use Bus.OutgoingHeaders - then you can look at that info at the publisher and decided what to do with it.
这篇关于NServiceBus 在订阅者订阅时发送信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!