public function testCreateClient() { $server = stream_socket_server('tcp://localhost:37235'); $loop = $this->getMock('React\\EventLoop\\LoopInterface'); $factory = new Factory($loop); $client = $factory->createClient(array('host' => 'localhost', 'port' => 37235)); $this->assertInstanceOf('React\\Stomp\\Client', $client); }
protected function getClient($loop, array $options = array()) { $factory = new Factory($loop); if (false === getenv('STOMP_PROVIDER')) { throw new \RuntimeException('STOMP_PROVIDER environment variable is not set'); } $provider = getenv('STOMP_PROVIDER'); $configFile = sprintf('%s/%s.php', realpath(__DIR__ . '/../../../../examples/config'), $provider); if (!file_exists($configFile)) { throw new \RuntimeException(sprintf('Invalid STOMP_PROVIDER: No config file found at %s', $configFile)); } $default = (require $configFile); $options = array_merge($default, $options); return $factory->createClient($options); }
/** * {@inheritdoc} */ public function register(GloubsterServerInterface $server) { $server['stomp-client.started'] = false; $server['stomp-client'] = $server->share(function (GloubsterServer $server) { $factory = new StompFactory($server['loop']); return $factory->createClient(array('host' => $server['configuration']['server']['host'], 'port' => $server['configuration']['server']['stomp-gateway']['port'], 'user' => $server['configuration']['server']['user'], 'passcode' => $server['configuration']['server']['password'], 'vhost' => $server['configuration']['server']['vhost'])); }); $server['dispatcher']->on('stop', function ($server) { $server['stomp-client']->disconnect(); $server['stomp-client.started'] = false; $server['monolog']->addInfo('STOMP Server shutdown'); }); $component = $this; $server['dispatcher']->on('start', function ($server) use($component) { $server['stomp-client']->on('error', array($server, 'logError')); $server['stomp-client']->connect()->then(Curry::bind(array($component, 'activateService'), $server), Curry::bind(array($server, 'throwError'))); $server['monolog']->addInfo('Connecting to STOMP Gateway...'); }); }
public function __construct(LoopInterface $loop) { $this->loop = $loop; parent::__construct($loop); }