microservice1.py
1 |
import asyncio |
---|---|
2 |
from os import environ |
3 |
from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner |
4 |
|
5 |
|
6 |
class Component(ApplicationSession): |
7 |
"""
|
8 |
An application component calling the different backend procedures.
|
9 |
"""
|
10 |
|
11 |
async def onJoin(self, details): |
12 |
|
13 |
print(await self.call(u'com.myapp.update_variable', u'variable1',)) |
14 |
|
15 |
print(await self.call(u'com.myapp.update_variable', u'variable2', value=u'toto')) |
16 |
|
17 |
self.leave()
|
18 |
|
19 |
def onDisconnect(self): |
20 |
asyncio.get_event_loop().stop() |
21 |
|
22 |
|
23 |
if __name__ == '__main__': |
24 |
runner = ApplicationRunner( |
25 |
environ.get("AUTOBAHN_DEMO_ROUTER", u"ws://127.0.0.1:8080/ws"), |
26 |
u"realm1",
|
27 |
) |
28 |
runner.run(Component) |