App wrapper on top of ApplicationRunner
See original GitHub issueFrom: https://groups.google.com/forum/#!topic/autobahnws/lmztderi6N4
What I think is the biggest adoption issue, however, is the API. Autobahn should have a small cost of entry, and right now it doesnt. The hello world is not only hard to write using the documentation, but quite scary :
from twisted.python import log
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.wamp import ApplicationSession
from autobahn.twisted.wamp import ApplicationRunner
class ListenForEvent(ApplicationSession):
def __init__(self, config):
ApplicationSession.__init__(self)
self.config = config
def onConnect(self):
self.join(self.config.realm)
@inlineCallbacks
def onJoin(self, details):
callback =lambda x: log.msg("Received event %s" % x)
yield self.subscribe(callback,'un_evenement')
if __name__ =='__main__':
runner = ApplicationRunner(endpoint="tcp:127.0.0.1:8080",
url="ws://localhost:8080/ws",
realm="realm1")
runner.run(ListenForEvent)
We need a simplified wrapper for that, that can be used for simple use case : small applications, tests, etc. In the same fashion that flask and bottle make web programming much easier than Django. I’m suggesting to add something like this :
from autobahn.app import App
app = App(url="ws://localhost:8080/ws")
@event("event_name")
def handle(details):
app.log("Received event %s" % details)
if __name__ =='__main__':
app.run()
Sane defaults, doesn’t not cover all the use cases, but it’s enought for 80% of the dev. The goal is not to replace the other API, but rather offer something higher level we can show of in the first page of the documentation that would make people started quickly.
Issue Analytics
- State:
- Created 9 years ago
- Comments:44 (41 by maintainers)
Top GitHub Comments
subseded/fixed in https://github.com/crossbario/autobahn-python/issues/964
@DenJohX Agreed, not being able to automatically reconnect a python client (using ApplicationRunner) to crossbar.io is blocking me from using Autobahn. Is there a workaround?