Thruway WAMP2 上的内部客户端
Posted
技术标签:
【中文标题】Thruway WAMP2 上的内部客户端【英文标题】:Internal Client on Thruway WAMP2 【发布时间】:2014-10-02 03:40:49 【问题描述】:我正在开发一个内部客户端 + 身份验证模型的示例,如下所示。
现在我需要检索已连接会话的列表并从内部客户端拦截会话的关闭事件。
我想问是否有任何方法可以存档该任务?我正在考虑将该列表保存在 redis 中,但这意味着我必须重新编写 Thruway\Peer\Router
类,因为所需的变量现在是私有的,我们无法访问它们来扩展。
文件服务器.php
<?php
/**
* server.php
*/
require "../bootstrap.php";
require 'InternalClient.php';
require 'SimpleAuthProviderClient.php';
use Thruway\Peer\Router;
use Thruway\Transport\RatchetTransportProvider;
use React\EventLoop\Factory;
use Thruway\Manager\ManagerClient;
use Thruway\Transport\InternalClientTransportProvider;
$manager = new ManagerClient();
$loop = Factory::create();
$router = new Router($loop, $manager);
$router->addTransportProvider(new InternalClientTransportProvider($manager));
$internalTransportProvider = new InternalClientTransportProvider(new \InternalClient());
$router->addTransportProvider($internalTransportProvider);
$authMgr = new \Thruway\Authentication\AuthenticationManager();
$router->setAuthenticationManager($authMgr);
$router->addTransportProvider(new InternalClientTransportProvider($authMgr));
//Provide authentication for the realm: 'somerealm'
$authProvClient = new SimpleAuthProviderClient(["somerealm"]);
$router->addTransportProvider(new InternalClientTransportProvider($authProvClient));
$transportProvider = new RatchetTransportProvider("127.0.0.1", 9090);
$router->addTransportProvider($transportProvider);
$router->start();
文件 SimpleAuthProviderClient.php
<?php
/**
* SimpleAuthProviderClient.php
*/
require "../bootstrap.php";
/**
* Class SimpleAuthProviderClient
*/
class SimpleAuthProviderClient extends \Thruway\Authentication\AbstractAuthProviderClient
/**
* @return string
*/
public function getMethodName()
return 'simplysimple';
/**
* @param mixed $signature
* @param null $extra
* @return array
*/
public function processAuthenticate($signature, $extra = null)
if ($signature == "letMeIn")
return ["SUCCESS"];
else
return ["FAILURE"];
文件 InternalClient.php
<?php
/**
* InternalClient.php
*/
require "../bootstrap.php";
/**
* Class InternalClient
*/
class InternalClient extends Thruway\Peer\Client
function __construct()
parent::__construct("realm1");
/**
* @param \Thruway\AbstractSession $session
* @param \Thruway\Transport\TransportInterface $transport
*/
public function onSessionStart($session, $transport)
echo "--------------- Hello from InternalClient ------------";
$this->getCallee()->register($this->session, 'com.example.getphpversion', [$this, 'getPhpVersion']);
function start()
/**
* @return array
*/
function getPhpVersion()
return [phpversion()];
【问题讨论】:
【参考方案1】:出于参考目的,此问题已在 Github 上回答。
如果您订阅事件wamp.metaevent.session.on_join
和wamp.metaevent.session.on_leave
,您将收到通知。该事件返回 1 个类似的参数:
"realm":"realm1",
"authprovider":null,
"authid":"username",
"authrole":"none",
"authmethod":"simplysimple",
"session":6016528494456948
【讨论】:
以上是关于Thruway WAMP2 上的内部客户端的主要内容,如果未能解决你的问题,请参考以下文章
Storm集群上的开发 ,Storm的内部原理,storm提交任务的过程