1

I have been using crossbar for awhile and I love it. I have a question about the best way to run workers that will connect to an external router. I was using "crossbar start" and creating a config file that connected to the router and this worked great.

Recently my requirements have changed to where I would like to pass the router url and realm into the config file via environment variables. After trial and error I concluded that this was not possible with the current XBAR implementation.

I then looked at creating an application runner using the following where I retrieved the realm and the url from config vars

runner = ApplicationRunner(url=url, realm=realm)
runner.run(AppSession)

This works but I then noticed my server would go down periodically. After root causing, I realized that the reverse proxy was timing out the connection after 1 hour of inactivity. Looking at the server logs, I got the "onDisconnect" callback. Looking at the XBAR application runner documentation it states the following

This class is a convenience tool mainly for development and quick hosting
of WAMP application components.

I have my service running in a "runit" script as a Daemon. Some quick fixes I came up with are

  • Kill the runner and let the daemon restart the service
  • Explicitly perform the join process on any disconnects

All of these were starting to feel really hacky given the XBAR folks explicitly state that the ApplicationRunner is a development tool. Anyone know if there is something I can use other than an application runner OR some way I can get environment variables into the config.json file?

As a temporary workaround I am using sed. Here is my config file

{
    "controller": {
    },
    "workers": [
    {
        "type": "container",
        "options": {
            "pythonpath": [".."]
        },
        "components": [
            {
                "type": "class",
                "classname": "src.app_session.AppSession",
                "realm": "%%%ROUTER_REALM%%%",
                "transport": {
                    "type": "websocket",
                    "endpoint": {
                        "type": "tcp",
                        "host": "%%%ROUTER_HOST%%%",
                        "port": %%%ROUTER_PORT%%%
                    },
                    "url": "%%%ROUTER_PROTOCOL%%%://%%%ROUTER_HOST%%%/ws"
                }
            }
        ]
     }
  ]

}

And my runit script is

#!/bin/bash

# Update the ROUTER config parameters
sed -i -e "s/%%%ROUTER_HOST%%%/${ROUTER_HOST}/g" /app/.crossbar/config.json
sed -i -e "s/%%%ROUTER_PORT%%%/${ROUTER_PORT}/g" /app/.crossbar/config.json
sed -i -e "s/%%%ROUTER_REALM%%%/${ROUTER_REALM}/g" /app/.crossbar/config.json
sed -i -e "s/%%%ROUTER_PROTOCOL%%%/${ROUTER_PROTOCOL}/g" /app/.crossbar/config.json

cat /app/.crossbar/config.json

cd /app/
exec crossbar start
echappy
  • 533
  • 5
  • 13
  • Not a solution, but if you were running your component as a guest instead of in a container, you could pass in the required data - see http://crossbar.io/docs/Process-Environments/ – gzost Sep 25 '15 at 17:21

1 Answers1

0

There is indeed no mechanism with Crossbar.io to do what you want. From the side of the project there are no plans to implement this as a feature. We want to concentrate on the management API, which will enable to dynamically manage Crossbar.io.

gzost
  • 2,375
  • 1
  • 18
  • 25