单个AppSession无法订阅和发布同一主题

时间:2014-11-16 22:10:03

标签: python autobahn crossbar

基于简单的Hello World示例,我在发布时将oncounter主题替换为onhello主题。这意味着AppSession正在订阅它自己发布的主题。我猜它应该能够收到自己的消息,但看起来并不是这样。有没有办法做到这一点?

有关可重复的示例:


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)

运行@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) 后,我看到crossbar start主题已发布,但未收到。

1 个答案:

答案 0 :(得分:3)

原因是,默认情况下,即使发布商自己订阅了发布的主题,发布商也不会发布活动。

您可以通过向options提供publish()参数来改变该行为:

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