基于简单的helloworld示例,我在发布时将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)
运行crossbar start
之后,我看到onhello
主题正在发布,但是没有收到它。在
原因是,在默认情况下,即使发布者自己订阅了发布到的主题,也不会发布事件。在
您可以通过将
options
参数提供给publish()
来更改该行为:相关问题 更多 >
编程相关推荐