I am following the basic wamp pubsub examples in the github code:
This example publishes messages from within the class:
class Component(ApplicationS
Upon your app session joining the WAMP realm, it sets a reference to itself on the app session factory:
class MyAppComponent(ApplicationSession):
... snip
def onJoin(self, details):
if not self.factory._myAppSession:
self.factory._myAppSession = self
You then can access this session from elsewhere in your code, e.g.
@inlineCallbacks
def pub():
counter = 0
while True:
## here we can access the app session that was created ..
##
if session_factory._myAppSession:
session_factory._myAppSession.publish('com.myapp.topic123', counter)
print("published event", counter)
else:
print("no session")
counter += 1
yield sleep(1)
pub()