Looks like I answered my own question.... or is there another way to use an imported component that is written in 3.4 with asyncio?
2015-01-15 11:37:53-0500 [Container 5730] Entering event loop ..
2015-01-15 11:37:53-0500 [Container 5730] Warning: process utilities not available
2015-01-15 11:37:53-0500 [Controller 5718] Container with ID 'worker2' and PID 5730 started
2015-01-15 11:37:53-0500 [Controller 5718] Container 'worker2': PYTHONPATH extended
2015-01-15 11:37:54-0500 [Container 5730] ERROR: failed to import class hello.Main.MyBackendComponent ("invalid syntax (Main.py, line 36)")
2015-01-15 11:37:54-0500 [Controller 5718] Traceback (most recent call last):
2015-01-15 11:37:54-0500 [Controller 5718] File "/usr/local/lib/python2.7/dist-packages/crossbar/controller/node.py", line 190, in run_node_config
2015-01-15 11:37:54-0500 [Controller 5718] yield self._run_node_config(config)
2015-01-15 11:37:54-0500 [Controller 5718] ApplicationError: ApplicationError('crossbar.error.cannot_import', args = (u'ERROR: failed to import class hello.Main.MyBackendComponent ("invalid syntax (Main.py, line 36)")', u'Traceback (most recent call last):\n File "/usr/local/lib/python2.7/dist-packages/crossbar/worker/container.py", line 214, in start_container_component\n module = importlib.import_module(module_name)\n File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module\n __import__(name)\n File "/home/dave/PycharmProjects/CrossbarDemos/HelloDemo/hello/Main.py", line 36\n reg = yield from self.register(utcnow, \'com.timeservice.now\')\n ^\nSyntaxError: invalid syntax\n'), kwargs = {})
2015-01-15 11:37:54-0500 [Controller 5718] Main loop terminated.
import json
import datetime
import asyncio
from autobahn.asyncio import wamp, websocket
class DavesTestClass(object):
def __init__(self):
self.name = 'Dave'
self.age = 51
class MyBackendComponent(wamp.ApplicationSession):
"""
Application code goes here. This is an example component that provides
a simple procedure which can be called remotely from any WAMP peer.
It also publishes an event every second to some topic.
"""
def onConnect(self):
self.join("realm1")
@asyncio.coroutine
def onJoin(self, details):
def jsonDefault(o): # https://freepythontips.wordpress.com/2013/08/08/storing-and-loading-data-with-json/
return o.__dict__
# Register a procedure for remote calling
def utcnow():
now = datetime.datetime.utcnow()
time = now.strftime("%Y-%m-%dT%H:%M:%SZ") # six.u()
print(time)
return time
reg = yield from self.register(utcnow, 'com.timeservice.now')
print("Registered procedure with ID {}".format(reg.id))
# Publish events to a topic
dave = DavesTestClass()
# print(dave)
while True:
objToSend = json.dumps(dave, default=jsonDefault, indent=4)
self.publish('com.myapp.topic1', objToSend)
print('Published: ', objToSend)
yield from asyncio.sleep(1)
# if __name__ == '__main__':
# # 1) create a WAMP router factory
# router_factory = wamp.RouterFactory()
#
# # 2) create a WAMP router session factory
# session_factory = wamp.RouterSessionFactory(router_factory)
#
# # 3) Optionally, add embedded WAMP application sessions to the router
# session_factory.add(MyBackendComponent())
#
# # 4) create a WAMP-over-WebSocket transport server factory
# transport_factory = websocket.WampWebSocketServerFactory(session_factory, debug=False, debug_wamp=False)
#
# # 5) start the server
# loop = asyncio.get_event_loop()
# coro = loop.create_server(transport_factory, '127.0.0.1', 8080)
# server = loop.run_until_complete(coro)
# try:
# # 6) now enter the asyncio event loop
# loop.run_forever()
# except KeyboardInterrupt:
# pass
# finally:
# server.close()
# loop.close()
{
"controller": {
},
"workers": [
{
"type": "router",
"options": {
"pythonpath": [".."]
},
"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": {
"/": {
"type": "static",
"directory": "../hello/web"
},
"ws": {
"type": "websocket"
}
}
}
]
},
{
"type": "container",
"options": {
"pythonpath": [".."]
},
"components": [
{
"type": "class",
"classname": "hello.Main.MyBackendComponent",
"realm": "realm1",
"transport": {
"type": "websocket",
"endpoint": {
"type": "tcp",
"host": "127.0.0.1",
"port": 8080
},
"url": "ws://127.0.0.1:8080/ws"
}
}
]
}
]
}
"components": [
// WAMP app components running side-by-side with this router
],
{ "type": "container", "options": { "pythonpath": [".."] }, "components": [ { "type": "class",
"classname": "hello.hello.AppSession",
"realm": "realm1", "transport": { "type": "websocket", "endpoint": { "type": "tcp", "host": "127.0.0.1", "port": 8080 }, "url": "ws://127.0.0.1:8080/ws" } } ] }
autobahn.twisted.wamp.ApplicationSession
.
{
"controller": {
},
"workers": [
{
"type": "router",
"options": {
"title": "WAMP Router"
},
"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": {
"/": {
"type": "static",
"directory": "<Name of your front end project directory if you want to debug at the same time!>"
},
"ws": {
"type": "websocket"
}
}
}
]
}
]
}
if __name__ == '__main__':
runner = ApplicationRunner(url="ws://localhost:8080/ws", realm="realm1")
runner.run(AppSession)