将角色关联到Crossbar组件

时间:2015-07-22 12:20:13

标签: python autobahn crossbar

我想运行一个具有特定角色的component。但每次我设置"角色"我的组件的参数Crossbar服务器运行就像它有一个无限循环:我第一次进入页面,一切都很完美,但如果我刷新或打开另一个窗口到同一页面,或者即使另一个客户打开此页面,页面一遍又一遍地加载......

然后,如果我停止横杆服务器,我会在日志中多次显示此消息:[Controller 4422] waiting for 4433 to exit...

这是我的conf.json:

{
  "controller": {
  },
  "workers": [
    {
      "type": "router",
      "options": {
        "pythonpath": [".."]
      },
      "realms": [
        {
          "name": "realm1",
          "roles": [
            {
              "name": "anonymous",
              "permissions": [
                {
                  "uri": "*",
                  "publish": true,
                  "subscribe": true,
                  "call": true,
                  "register": false
                }
              ]
            },
            {
              "name": "wamp_app",
              "permissions": [
                {
                  "uri": "*",
                  "publish": true,
                  "subscribe": true,
                  "call": true,
                  "register": true
                }
              ]
            }
          ]
        }
     ],
     "transports": [
       {
         "type": "web",
         "endpoint":{
           "type":"tcp",
           "port":8000
         },
         "paths": {
           "/": {
             "type": "wsgi",
             "module": "cyto_multihead.wsgi",
             "object": "application"
            },
            "lp": {
              "type": "longpoll"
            },
            "static": {
              "type": "static",
              "directory": "../static/"
            },
            "ws": {
              "type": "websocket"
            }
          }
        }
      ],
      "components": [
        {
          "type": "class",
          "classname": "crossbar_test.crossbar.MyComponent",
          "realm": "realm1",
          "role": "wamp_app"
        }
      ]
    }
  ]
}

我的文件放置如下:

my_project_directory/
  .crossbar/
    config.json
  crossbar_test/
    crossbar.py

此外,如果我没有指定角色,则服务器不会从此错误开始:

[Router      28146] --- <exception caught here> ---
[Router      28146] File "/usr/local/lib/python2.7/dist-packages/twisted/internet/defer.py", line 150, in maybeDeferred
[Router      28146] result = f(*args, **kw)
[Router      28146] File "/usr/local/lib/python2.7/dist-packages/crossbar/worker/router.py", line 510, in start_router_component
[Router      28146] self.session_factory.add(session, authrole=config.get('role', 'anonymous'))
[Router      28146] File "/usr/local/lib/python2.7/dist-packages/crossbar/router/session.py", line 470, in add
[Router      28146] self._app_sessions[session] = RouterApplicationSession(session, self._routerFactory, authid, authrole)
[Router      28146] File "/usr/local/lib/python2.7/dist-packages/crossbar/router/session.py", line 88, in __init__
[Router      28146] assert(authrole is None or isinstance(authrole, six.text_type))
[Router      28146] exceptions.AssertionError:
[Router      28146] 'Failure while invoking procedure <bound method RouterWorkerSession.start_router_component of <crossbar.worker.router.RouterWorkerSession object at 0x7fc1a4484cd0>> registered under "crossbar.node.conan.worker.worker1.start_router_component".'
[Controller  28135] Traceback (most recent call last):
[Controller  28135]   File "/usr/local/lib/python2.7/dist-packages/crossbar/controller/node.py", line 183, in run_node_config
[Controller  28135]     yield self._run_node_config(config)
[Controller  28135] ApplicationError: ApplicationError('wamp.error.runtime_error', args = (), kwargs = {})
[Controller  28135] sending TERM to subprocess 28146
[Controller  28135] waiting for 28146 to exit...
[Router      28146] Received SIGTERM, shutting down.
[Router      28146] Connection to node controller lost.
[Router      28146] Main loop terminated.
[Controller  28135] Worker 28146: Process connection gone (Connection was closed cleanly.)
[Controller  28135] Main loop terminated.

我的配置有什么问题?

1 个答案:

答案 0 :(得分:0)

我认为问题来自以下配置:

"/": {
  "type": "wsgi",
  "module": "cyto_multihead.wsgi",
  "object": "application"
},

如果您更改配置,例如:

"/": {
  "type": "static",
  "directory": "../hello/web"
},

Crossbar将成功运行。