Single AppSession can't subscribe to and publish on the same topic

358 views Asked by At

Based on the simple Hello World example, I replace the oncounter topic with the onhello one when publishing. That would mean the AppSession is subscribing to a topic it is itself publishing. I'd guess it should be able to receive its own messages but it looks like it doesn't. Is there a way to do this?

For a reproducible example:


from twisted.internet.defer import inlineCallbacks

from autobahn.twisted.util import sleep from autobahn.twisted.wamp import ApplicationSession

class AppSession(ApplicationSession):

@inlineCallbacks
def onJoin(self, details):

    def onhello(msg):
        print("event for 'onhello' received: {}".format(msg))
    sub = yield self.subscribe(onhello, 'com.example.onhello')

    counter = 0
    while True:

        yield self.publish('com.example.onhello', counter)
        print("published to 'onhello' with counter {}".format(counter))
        counter += 1

        yield sleep(1)

After running crossbar start, I see the onhello topic being published, but it is not received.

1

There are 1 answers

1
oberstet On BEST ANSWER

The reason is, that - by default - a publisher does not get an event published even if the publisher is itself subscribed to the topic published to.

You can alter that behavior by provided an options argument to publish():

yield self.publish('com.example.onhello', counter,
   options = autobahn.wamp.types.PublishOptions(excludeMe = False))