Show pageOld revisionsBacklinksAdd to bookExport to PDFBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== WAMP ====== ===== Concepts ===== A Crossbar.io **node** is a single instance of the Crossbar.io software running in a specific **node directory** There are two types of processes running within a Crossbar.io node: * one process **controller** * multiple **workers** Workers: * Native Workers * Routers: WAMP routing services between WAMP clients * Containers: application components written in Python * Guest Workers: arbitrary programs spawned ===== WAMP router ===== Use python **only** 2.x prereq <code> apt-get install python-virtualenv python-dev libffi-dev \ libssl-dev libxml2-dev libxslt1-dev libyaml-dev </code> <code> pip install crossbar[tls,msgpack,manhole,system] pip install setproctitle </code> ATTENZIONE con la versione 0.11.1, commentare la riga 232 di lib/lib/python2.7/site-packages/crossbar/controller/process.py <code> #ep['meta'] = e(None) </code> Create new router node <code> cd /path/ crossbar init --template default </code> .crossbar/config.json <code> { "controller": { }, "workers": [ { "type": "router", "options": { "pythonpath": [".."] }, "manhole": { "endpoint": { "type": "tcp", "port": 6022 }, "users": [ { "user": "scipio", "password": "z" } ] }, "realms": [ { "name": "realm1", "roles": [ { "name": "anonymous", "permissions": [ { "uri": "*", "publish": true, "subscribe": true, "call": true, "register": true } ] } ] } ], "transports": [ { "type": "web", "endpoint": { "type": "tcp", "port": 8080 }, "paths": { "ws": { "type": "websocket", "debug": false } } } ] } ] } </code> Start node <code> crossbar start </code> supervisor config <code> [program:wamp] command=/opt/wamp/lib/bin/crossbar start --cbdir /opt/wamp/.crossbar user=wamp autostart=true </code> ==== http bridge publisher and caller === An http POST request can emit WAMP event, or we can call an RPC via http POST. <code> "transports": [ { "type": "web", "endpoint": { "type": "tcp", "port": 8080 }, "paths": { ... "push": { "type": "publisher", "realm": "realm1", "role": "anonymous" }, "call": { "type": "caller", "realm": "realm1", "role": "anonymous" } } } ] </code> example of event publish <code> import requests requests.post("http://router_ip/push", json={ 'topic': 'great_topic' 'args': [some, params, to, pass, along, if, you, need, to] }) </code> example of event post with curl <code> curl --connect-timeout 3 \ -H "Content-Type: application/json" \ -d '{"topic": "vr.ztl.passaggi", "kwargs": {"uids":[1,2,3]}}' \ http://localhost:8081/push </code> example of RPC call with curl <code> curl --connect-timeout 3 \ -H "Content-Type: application/json" \ -d '{"procedure": "vr.ztl.permessi.get", "args": ["EC316MP"]}' \ http://127.0.0.1:8081/call </code> ==== WSGI app (pyramid) ==== Create wsgi.py in same folder as setup.py <code> ini_path = '../development.ini' from pyramid.paster import get_app, setup_logging setup_logging(ini_path) application = get_app(ini_path, 'main') </code> Add to "paths" <code> "/": { "type": "wsgi", "module": "wsgi", "object": "application" }, </code> ===== WAMP node ===== Use python 3.x <code> pip install autobahn[asyncio,twisted] </code> projects/wamp/docs.txt Last modified: 2017/05/04 17:45by scipio