简体   繁体   中英

Autobahn pubsub, queues and topics?

The Autobahn documentation is a bit unclear on which/how clients receive messages once they are published. Out of the box it seems that a message is broadcast to all subscribers of a topic - they all get it. But is there any way to distribute a message to a single client? Something in the lines of a queue where multiple publishers add messages to a queue and messages are distributed to "free" subscribers, round robin style? Guess it can also be referred to as the Simple Pirate pattern.

As noted normally publish goes to all subscribers.

If you want to publish and direct to a specific subscriber(s), then you direct with the eligible parameter. Here is the WAMP doc:

http://autobahn.ws/python/reference/autobahn.wamp.html?highlight=eligible#autobahn.wamp.message.Publish

class autobahn.wamp.message.Publish(request, topic, args=None, kwargs=None, acknowledge=None, excludeMe=None, exclude=None, eligible=None, discloseMe=None)

In your case you would need to provide the list of eligible session ids eg eligible = ( 1,2,3, )

I don't have a v2 example, but, judging by the source, I'd guess something like:

self.publish(u'com.myapp.topic1',  eligible = [100, 200, 300] )

In v1 I used this technique to publish to a subset of the subscribers. In v2, I am using the subscription topic itself to limit who receives the message. So, I might create com.pub.m1, com.pub.m2, com.pub.m3, etc instead of com.pub, and my clients subscribe to the topic which dictates what they will receive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM