Can autobahn.twisted.wamp.Application do pub/sub?

你。 提交于 2019-12-24 11:58:31

问题


I would like to use some pub/sub features along with rpc from autobahn.twisted.wamp.Application

I'd prefer not to make a ApplicationSession class if I can get by without doing so.

Can registered rpc methods cause client subscriptions and publish? If they can, please show me how.


回答1:


Yes, sure:

def onEvent(msg):
   print("got event: {}".format(msg))

@app.register('com.example.triggersubscribe')
def triggerSubscribe():
   yield app.session.subscribe(onEvent, 'com.example.topic1')

When triggerSubscribe is called (e.g. remotely from another WAMP component), the callee (the WAMP component exposing com.example.triggersubscribe) will dynamically subscribe to com.example.topic1.

You can publish from within a registered procedure also of course: app.session.publish().

I have added the complete example (including JS client) here.



来源:https://stackoverflow.com/questions/25330339/can-autobahn-twisted-wamp-application-do-pub-sub

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!