Skip to content

Quick Start with Crossbar.io

Mulkave edited this page Nov 27, 2014 · 4 revisions

Quick Start with Crossbar.io

In the project directory:
  • Configure crossbar in .crossbar/config.json:
{
   "controller": {
   },
   "workers": [
      {
         "type": "router",
         "realms": [
            {
               "name": "minion",
               "roles": [
                  {
                     "name": "anonymous",
                     "permissions": [
                        {
                           "uri": "*",
                           "publish": true,
                           "subscribe": true,
                           "call": true,
                           "register": true
                        }
                     ]
                  }
               ]
            }
         ],
         "transports": [
            {
               "type": "websocket",
               "debug": true,
               "endpoint": {
                  "type": "tcp",
                  "port": 9090
               }
            }
         ]
      }
   ]
}
  • Run composer require 'vinelab/minion'
  • Create VersionProvider.php at the root and add the provider class:
require __DIR__.'/vendor/autoload.php';

use Vinelab\Minion\Provider;

class VersionProvider extends Provider {

    protected $prefix = 'com.minion.';

    public function boot()
    {
        // will be registered as com.minion.phpversion
        $this->register('phpversion', 'getPhpVersion');

        $this->call('phpversion')->then(function ($version) {
            var_dump('', "PHP Version: $version", '');
        });
    }

    public function getPhpVersion()
    {
        return phpversion();
    }
}
  • Create start.php at the root and add the script that will run our client:
require __DIR__.'/vendor/autoload.php';
require 'VersionProvider.php';

use Vinelab\Minion\Minion;

$m = new Minion();
$m->register('VersionProvider');
$m->run();
  • Run crossbar start
  • In another terminal tab run php start.php
From The Command Line
  • Tell composer about our provider class
    • Update composer.json with this content:
{
    "require": {
        "vinelab/minion": "dev-master"
    },
    "autoload": {
        "classmap": [
            "VersionProvider.php"
        ]
    },
    "minimum-stability": "dev"
}
  • Run composer dump-autoload
  • Run ./vendor/bin/minion run --register="VersionProvider"

make sure to stop the previous client first with Ctrl+c but keep crossbar running

Similar to VersionProvider you may have as many providers as you like and spread them across your application, then register them with either multiple --register options on the CLI or programatically using the register($provider) method.

Clone this wiki locally