addTransportProvider() public method

Add transport provider
public addTransportProvider ( Thruway\Transport\ClientTransportProviderInterface $transportProvider )
$transportProvider Thruway\Transport\ClientTransportProviderInterface
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     try {
         echo "Making a go at starting a Thruway worker.\n";
         $name = $input->getArgument('name');
         $config = $this->getContainer()->getParameter('voryx_thruway');
         $loop = $this->getContainer()->get('voryx.thruway.loop');
         $kernel = $this->getContainer()->get('wamp_kernel');
         $workerAnnotation = $kernel->getResourceMapper()->getWorkerAnnotation($name);
         if ($workerAnnotation) {
             $realm = $workerAnnotation->getRealm() ?: $config['realm'];
             $url = $workerAnnotation->getUrl() ?: $config['url'];
         } else {
             $realm = $config['realm'];
             $url = $config['url'];
         }
         $transport = new PawlTransportProvider($url);
         $client = new Client($realm, $loop);
         $client->addTransportProvider($transport);
         $kernel->setProcessName($name);
         $kernel->setClient($client);
         $kernel->setProcessInstance($input->getArgument('instance'));
         $client->start();
     } catch (\Exception $e) {
         $logger = $this->getContainer()->get('logger');
         $logger->addCritical("EXCEPTION:" . $e->getMessage());
         $output->writeln("EXCEPTION:" . $e->getMessage());
     }
 }
Example #2
0
 /**
  * @param array $options
  * @param LoopInterface $loop
  * @throws \Exception
  */
 function __construct(array $options, LoopInterface $loop = null, LoggerInterface $logger = null)
 {
     $this->options = $options;
     $this->client = new Client($options['realm'], $loop);
     /*
      * Add the transport provider
      * TODO: Allow for multiple transport providers
      */
     $url = isset($options['url']) ? $options['url'] : null;
     $pawlTransport = new PawlTransportProvider($url);
     if ($logger) {
         $pawlTransport->getManager()->setLogger($logger);
     }
     $this->client->addTransportProvider($pawlTransport);
     $this->client->setReconnectOptions($options);
     /*
      * Authentication on challenge callback
      */
     if (isset($options['onChallenge']) && is_callable($options['onChallenge']) && isset($options['authmethods']) && is_array($options['authmethods'])) {
         $this->client->setAuthMethods($options['authmethods']);
         $this->client->on('challenge', function (ClientSession $session, ChallengeMessage $msg) use($options) {
             $token = $options['onChallenge']($session, $msg->getAuthMethod());
             $session->sendMessage(new AuthenticateMessage($token));
         });
     }
     if (isset($this->options['onClose']) && is_callable($this->options['onClose'])) {
         $this->on('close', $this->options['onClose']);
     }
     /*
      * Handle On Open event
      *
      */
     $this->client->on('open', function (ClientSession $session, TransportInterface $transport) {
         $this->transport = $transport;
         $this->emit('open', [$session]);
     });
     /*
      * Handle On Close event
      */
     $this->client->on('close', function ($reason) {
         $this->emit('close', [$reason]);
     });
     $this->client->on('error', function ($reason) {
         $this->emit('error', [$reason]);
     });
 }
Example #3
0
 /**
  * Constructor
  *
  * @param array $options
  * @param \React\EventLoop\LoopInterface $loop
  * @throws \Exception
  */
 public function __construct(array $options, LoopInterface $loop = null)
 {
     $this->options = $options;
     $this->client = new Client($options['realm'], $loop);
     $url = isset($options['url']) ? $options['url'] : null;
     $pawlTransport = new PawlTransportProvider($url);
     $this->client->addTransportProvider($pawlTransport);
     $this->client->setReconnectOptions($options);
     //Set Authid
     if (isset($options['authid'])) {
         $this->client->setAuthId($options['authid']);
     }
     //Register Handlers
     $this->handleOnChallenge();
     $this->handleOnOpen();
     $this->handleOnClose();
     $this->handleOnError();
 }
Example #4
0
 /**
  * Constructor
  *
  * @param array $options
  * @param \React\EventLoop\LoopInterface $loop
  * @throws \Exception
  */
 public function __construct(array $options, LoopInterface $loop = null)
 {
     $this->options = $options;
     $this->client = new Client($options['realm'], $loop);
     $url = isset($options['url']) ? $options['url'] : null;
     $pawlTransport = new PawlTransportProvider($url);
     $this->client->addTransportProvider($pawlTransport);
     $this->client->setReconnectOptions($options);
     /*
      * Authentication on challenge callback
      */
     if (isset($options['onChallenge']) && is_callable($options['onChallenge']) && isset($options['authmethods']) && is_array($options['authmethods'])) {
         $this->client->setAuthMethods($options['authmethods']);
         $this->client->on('challenge', function (ClientSession $session, ChallengeMessage $msg) use($options) {
             $token = call_user_func_array($options['onChallenge'], [$session, $msg->getAuthMethod(), $msg]);
             $session->sendMessage(new AuthenticateMessage($token));
         });
     }
     //Set Authid
     if (isset($options['authid'])) {
         $this->client->setAuthId($options['authid']);
     }
     if (isset($this->options['onClose']) && is_callable($this->options['onClose'])) {
         $this->on('close', $this->options['onClose']);
     }
     /*
      * Handle On Open event
      *
      */
     $this->client->on('open', function (ClientSession $session, TransportInterface $transport) {
         $this->transport = $transport;
         $this->emit('open', [$session]);
     });
     /*
      * Handle On Close event
      */
     $this->client->on('close', function ($reason) {
         $this->emit('close', [$reason]);
     });
     $this->client->on('error', function ($reason) {
         $this->emit('error', [$reason]);
     });
 }
Example #5
0
 /**
  *
  * @param \Thruway\ClientSession $session
  * @param \Thruway\Transport\TransportInterface $transport
  */
 public function onSessionStart($session, $transport)
 {
     $session->register('add_command', [$this, 'addCommand']);
     $session->register('status', [$this, 'status']);
     $session->register('start_process', [$this, 'startProcess']);
     $session->register('stop_process', [$this, 'stopProcess']);
     $session->register('restart_process', [$this, 'restartProcess']);
     $session->register('add_instance', [$this, 'addInstance']);
     //Congestion Manager Client.  This needs to be a separate client because it needs to listen on the main realm and not `process_manager`.
     $config = $this->container->getParameter('voryx_thruway');
     $congestionManager = new Client($config['realm'], $session->getLoop());
     $congestionManager->addTransportProvider(new PawlTransportProvider($config['trusted_url']));
     $congestionManager->on('open', function (ClientSession $session) {
         $session->subscribe("thruway.metaevent.procedure.congestion", [$this, "onCongestion"]);
     });
     $congestionManager->start(false);
 }
Example #6
0
 /**
  * @return Client
  * @throws \Exception
  */
 private function getShortClient()
 {
     $client = new Client($this->config['realm']);
     $client->setAttemptRetry(false);
     $client->addTransportProvider(new PawlTransportProvider($this->config['trusted_url']));
     return $client;
 }
<?php

require __DIR__ . '/vendor/autoload.php';
use Thruway\ClientSession;
use Thruway\Peer\Client;
use Thruway\Transport\PawlTransportProvider;
$client = new Client("realm1");
$client->addTransportProvider(new PawlTransportProvider("ws://127.0.0.1:8080/ws"));
$title = $_GET['title'];
$message = $_GET['message'];
$type = $_GET['type'];
$notification['title'] = $title;
$notification['message'] = $message;
$notification['type'] = $type;
$notification = json_encode($notification);
echo "\n {$notification} \n";
//die();
$client->on('open', function (ClientSession $session) {
    global $notification;
    $session->publish('pcaudit.broadcastmessage', [$notification], [], ["acknowledge" => true])->then(function () {
        echo "Publish Acknowledged!\n";
        die;
    }, function ($error) {
        // publish failed
        echo "Publish Error {$error}\n";
        die;
    });
});
$client->start();
Example #8
0
<?php

require 'bootstrap.php';
use Thruway\ClientSession;
use Thruway\Peer\Client;
use Thruway\Transport\PawlTransportProvider;
$client = new Client("realm1");
$client->addTransportProvider(new PawlTransportProvider("ws://127.0.0.1:9090/"));
$client->on('open', function (ClientSession $session) {
    // 1) subscribe to a topic
    $onevent = function ($args) {
        echo "Event {$args[0]}\n";
    };
    $session->subscribe('com.myapp.hello', $onevent);
    // 2) publish an event
    $session->publish('com.myapp.hello', ['Hello, world from PHP!!!'], [], ["acknowledge" => true])->then(function () {
        echo "Publish Acknowledged!\n";
    }, function ($error) {
        // publish failed
        echo "Publish Error {$error}\n";
    });
    // 3) register a procedure for remoting
    $add2 = function ($args) {
        return $args[0] + $args[1];
    };
    $session->register('com.myapp.add2', $add2);
    // 4) call a remote procedure
    $session->call('com.myapp.add2', [2, 3])->then(function ($res) {
        echo "Result: {$res}\n";
    }, function ($error) {
        echo "Call Error: {$error}\n";