NServiceBus 过滤消息给订阅者 [英] NServiceBus filtering messages to subscribers

查看:45
本文介绍了NServiceBus 过滤消息给订阅者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 NService 总线,我想知道如何在发送消息时过滤消息,以便它们只发送给特定的订阅者.

I'm just getting started with NService bus and I want to know how to filter message when I send them so that they only go to particular subscribers.

例如,假设我有一个包含分类产品的数据库.我的发布者将每 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 assuming that I can get the subscriber to send the category they are interested in, I then would like to only publish messages about products in a particular category to subscribers that are interested in them.

类别是动态的,因此我无法为不同的类别创建不同的消息.因此,出于这个原因,我假设所有订阅者都必须订阅相同的已发布 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.

为了消除一些混淆,这里有另一个更接近真实情况的例子.

To clear up some confusion, here's another example that's closer to the real thing.

我的发布者的工作是根据标签通知订阅者有关 stackoverflow 上的新帖子.但我不希望发布者在 stackoverflow 中查询没人感兴趣的标签……更不用说这样做的开销了.

My publisher's job is to notify subscribers about new posts on stackoverflow based on tags. But I don't want the publisher to be querying stackoverflow for tags that no-one is interested in... not to mention to overhead of doing something like that.

因此,当订阅者订阅时,他们会注册他们的兴趣以及一些元数据,告诉发布者他们对哪些帖子感兴趣 - 例如帖子标记为 NServiceBus.

So when a subscriber subscribes, they register their interest along with some metadata telling the publisher what posts they are interested in - e.g. posts tagged NServiceBus.

现在发布者知道他们必须监视标记为 NServiceBus 的新帖子的 stackoverflow 并且可以开始这样做.

Now the publisher knows that they have to monitor stackoverflow for new posts tagged NServiceBus and can start doing just that.

因此,当有一个用 NServiceBus 标记的新帖子并且我的发布者去通知它的订阅者时,我希望它只通知对该标签感兴趣的订阅者......而不是订阅者对不同的标签感兴趣.

So when there is a new post tagged with NServiceBus and my publisher goes to notify it's subscribers, I want it to only notify the subscribers that are interested in that tag... and not subscribers that are interested in different tags.

更有意义?

我刚刚开始这个项目,所以如果我走错了路,我会很感激你的提醒和使用不同工具集的建议.

I'm just getting started on this project, so if I'm going down the wrong road I'd appreciate a heads up and suggestions to use a different set of tools.

推荐答案

假设您使分类订阅起作用,广播类别和相关产品并让每个端点只忽略它不关心的产品就足够了关于.否则,您必须为每个产品创建一条消息并包含类别,以便端点可以忽略配置的类别.

Assuming you get the categorization subscriptions to work, it should be sufficient to broadcast the category and associated products and have each endpoint just ignore the products it doesn't care about. Otherwise you'd have to create a message per product and include the category so endpoint can ignore configured categories.

这篇关于NServiceBus 过滤消息给订阅者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆