Search code examples
autobahn

Calling dispatch in subscribe in Autobahn


I am using Autobahn and I have an implementation-specific question.

I am trying to figure out how to send a notice to all connected clients (including the newly subscribed client) upon a client subscribing to a topic. Here's the code (edited down for clarity):

@exportSub("", True)
def subscribe(self, topicUriPrefix, topicUriSuffix):
topic_uri = "%s%s" % (topicUriPrefix, topicUriSuffix) 
    self.client.dispatch(topic_uri, {"msg":"WTF"})
return True

Yet, I'm not seeing the newly subscribed message receive this dispatch. The dispatch call is returning None.

What's happening here?


Solution

  • I figured this out. A client must first be subscribed to a topic before receiving a message sent via dispatch(). This means that the dispatch() cannot be called inside subscribe if one expect the subscribing client to receive the message. I worked around this problem by building a simple message queue and calling dispatch on the protocol instance for any queued messages.