Rebus subscriber-publisher system. Process message only by single subscriber

浪尽此生 提交于 2019-12-24 15:37:58

问题


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. Forgot to mention. I can't subscribe to the message only with one subscriber, because subscriberss can go online/offline all the time.


回答1:


But some messages should be processed only by single subscriber

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. mapping a message type to an endpoint
  2. "sending" the message instead of "publishing" it

You do (1) like this:

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

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.

You do (2) like this:

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

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

I hope that does the trick for you :)



来源:https://stackoverflow.com/questions/36715599/rebus-subscriber-publisher-system-process-message-only-by-single-subscriber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!