NServiceBus 在订阅者订阅时发送信息

发布于 2024-11-19 01:23:36 字数 494 浏览 1 评论 0原文

我刚刚开始使用 NServiceBus,并且已经启动并运行了一个非常基本的实现 - 非常类似于 PubSub 示例应用程序。

我想做的是当订阅者订阅时发送一些信息。

例如,假设我有一个包含已分类产品的数据库。我的发布者将每 N 秒检查一次数据库,并在将新产品添加到数据库时发送消息。

但每个订阅者只对特定类别感兴趣,我想在他们订阅时发送该类别,以便发布者知道检查数据库中该类别的新产品。

类别是动态的,因此我无法为不同的类别创建不同的消息。因此,出于这个原因,我假设所有订阅者都必须订阅相同的已发布的 IMessage

注意:我也希望使用此信息来过滤 NServiceBus 发送给订阅者的消息,但我想我会 将其作为一个单独的问题发布

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.

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.

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.

NOTE: I do also wish to use this information to then filter the messages NServiceBus sends to subscribers, but I thought I would post that as a separate question.

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

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

发布评论

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

评论(2

固执像三岁 2024-11-26 01:23:36

您可以实现 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.

星星的軌跡 2024-11-26 01:23:36

我已经有一段时间没有使用 NServiceBus 了,但我认为 NServiceBus 没有任何事件可以在订阅发生时通知您。

尽管如此,我认为您可能在一个过于精细的水平上接近您的解决方案。

您通常会订阅企业通常感兴趣的事件。在您的情况下,当添加新产品时。一个更简单的解决方案是简单地订阅 ProductAddedEvent 并让您的订阅者忽略任何它不感兴趣的消息。

自我推销警告! :) --- 我这里有一个 FOSS ESB(仍然是 CTP): http://shuttle.codeplex.com/< /a>

我们在总线的各个部分使用管道,您给了我一个在 StartupPipeline 上包含 SubscriptionRequested 事件的想法。

I haven't worked with NServiceBus for quite some time but I don't think NServiceBus has any events to notify you when a subscription has taken place.

Be that as it may I think you may be approaching your solution on a level that is too fine.

You usually subscribe to events that the business is typically interested in. In your case when a new product is added. A simpler solution would be to simply subscribe to say a ProductAddedEvent and have your subscriber ignore any messages that it is not interested in.

Self-promotion warning! :) --- I have a FOSS ESB available here (still CTP): http://shuttle.codeplex.com/

We make use of pipelines for various parts of the bus and you have given me an idea to include a SubscriptionRequested event on the StartupPipeline.

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