I follow what you're saying, but how should I be creating the 2nd session? Below is the basic structure of what I've done, which is admittedly a little different. I'd like to use different modules because I want to try to keep things logically separated.
module1.py:
----------------
import module2
class MyClassSession1(ApplicationSession):
# This class/session is a native Crossbar worker configured in config.json.
# It runs on realm "realm1" and registers the "first" RPC.
def onJoin(self, details):
yield self.register(
"com.myapp.realm1.myproc",
module2.myProc2,
RegisterOptions(details_arg="details"))
module2.py
----------------
import module3
def myProc2(arg, details):
# This is the "first" RPC implementation.
return module3.MyClass3().myProc3(arg)
module3.py
----------------
results = {}
class MyClassSession3(ApplicationSession):
# This class/session is run via the ApplicationRunner below.
# It runs on realm "realm2" and calls the "second" RPC.
def onJoin(self, details):
results[self.config.extra["result_id"] = \
yield self.call(
"com.myapp.realm2.myproc",
self.config.extra["arg"])
self.leave()
class MyClass3(object):
def myProc3(self, arg):
result_id = uuid.uuid4().hex
runner = ApplicationRunner(
"wss://
127.0.0.1/ws", # same URL as original caller (browser) used for "realm1"
"realm2",
extra={"arg": arg,
"result_id": result_id})
runner.run(MyClassSession3)
result = copy.deepcopy(results[result_id])
del results[result_id]
return result
module4.py
----------------
def myProc4(arg):
# This is the second RPC implementation.
pass
class MyClassSession4(ApplicationSession):
# This class/session is a native Crossbar worker configured in config.json.
# It runs on realm "realm2" and registers the "second" RPC.
def onJoin(self, details):
yield self.register(
"com.myapp.realm2.myproc",
myProc4)
---------------------------------------------------------------------
Currently, when all of the above runs, the two native workers (one per unique realm, configured in config.json) appear to start OK via Crossbar. When I make a the call to the first RPC from a browser, it appears to come into the first session OK, get routed OK to module2.myProc2, which then instantiates module3.MyClass3 and invokes its myProc3 method. The ApplicationRunner appears to get created OK, but when its "run" method is invoked, I see the following in the Crossbar.io log:
2015-01-09 17:53:52-0500 [Router 28838] Unable to write to plugin cache /usr/local/lib/python2.7/dist-packages/twisted/plugins/dropin.cache: error number 13
2015-01-09 17:53:53-0500 [Router 28838] Unable to write to plugin cache /usr/local/lib/python2.7/dist-packages/twisted/plugins/dropin.cache: error number 13
2015-01-09 17:53:53-0500 [Router 28838] Starting factory <autobahn.twisted.websocket.WampWebSocketClientFactory instance at 0x42304b0c>
2015-01-09 17:53:53-0500 [Router 28838] Stopping factory <autobahn.twisted.websocket.WampWebSocketClientFactory instance at 0x42304b0c>
Meanwhile in the browser, I get an exception back with a "wamp.error.runtime_error" but no apparent additional descriptive text.
I know there must be some things I'm doing wrong, and I'm absolutely willing to do "best practices", but I'd really like to keep things logically separate in different modules if possible.
Thanks for your patience and any help/guidance,
Dave