重订订户-发布者系统.仅由单个订户处理消息 [英] Rebus subscriber-publisher system. Process message only by single subscriber

查看:76
本文介绍了重订订户-发布者系统.仅由单个订户处理消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个拥有一个发布者和几个订阅者的系统.但是某些消息应仅由单个订户处理.在我的情况下,发布者发送有关更改数据库中数据的消息,所有订阅者都可以访问相同的数据库,但是我不需要他们都更改相同的数据. 如何使用rebus来实现?

I have system with one publisher several subscribers. But some messages should be processed only by single subscriber. In my case publisher sends message about changing data in database, all subscribers has access to the same database, but I don't need them all change the same data. How can this be accomplished using rebus?

PS.忘了提.我不能只订阅一个订阅者,因为订阅者可以一直在线/离线.

PS. Forgot to mention. I can't subscribe to the message only with one subscriber, because subscriberss can go online/offline all the time.

推荐答案

但是某些消息应仅由单个订户处理

But some messages should be processed only by single subscriber

然后,您不应该将bus.Publish用于特定的消息类型-有一种机制可以将消息发送给一个特定的收件人,您应该使用-您可以通过

Then you should not use bus.Publish for that particular message type - there is a mechanism that sends messages to one particular recipient which you should use - you do it by

  1. 将消息类型映射到端点
  2. 发送"邮件而不是发布"邮件

您这样做(1):

Configure.With(...)
    .(...)
    .Routing(r => {
        r.TypeBased()
            .Map<YourMessage>("the_recipient");
    })
    .Start();

因此告诉Rebus,从队列the_recipient中获取其消息的任何人都是类型YourMessage 的消息的所有者,应视为该类型的隐式路由消息的自然接收者.

thus telling Rebus that whoever gets its messages from the queue the_recipient is the owner of messages of type YourMessage and should be considered the natural recipient for an implicitly routed message of that type.

您这样做(2):

await bus.Send(new YourMessage(...));

,然后Rebus会将邮件发送给邮件的自然所有者.

and then Rebus will send the message to the message's natural owner.

我希望这可以帮到您:)

I hope that does the trick for you :)

这篇关于重订订户-发布者系统.仅由单个订户处理消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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