可以在一个gatewayworker里同时设置两个businessworker?

0

RT:
我这样设置了两个businessworker,两个一个$worker->eventHandler ='Events_SIS';一个默认,但是Gateway的数据怎么定指定到哪个businessworker,上来处理啊?
设置两个businessworker是可以运行,但是不知道怎么指定gateway的消息到其中的一个Gateway.

已邀请:

喵了个咪

赞同来自:

gateway 可以设置消息路由,手册里有介绍

blogdaren - 乐于分享的PHP码农【http://www.blogdaren.com】

赞同来自:

方法就是楼上说的为gateway设置路由,主要是 $key 的定制, 以下是路由至特定businessworker参考代码:


$gateway->router = function($worker_connections, $client_connection, $cmd, $buffer){
$target_businessworker = array(
'ip' => '127.0.0.1', //填写目标 businessworker ip
'name' => 'demoBusiness2', //填写目标 businessworker name
'id' => rand(0, 2), //填写目标 businessworker id
);

$key = implode(':', array_values($target_businessworker));
empty($client_connection->businessworker_address) && $client_connection->businessworker_address = $key;

return $worker_connections[$client_connection->businessworker_addres];
};

veinliu

赞同来自:

谢谢两位,看了好久的手册都没有,找到,谢谢!

veinliu

赞同来自:

Notice: Undefined index: 127.0.0.1:BusinessWorker_SIS:0 in /var/www/html/GatewayWorker/Applications/YourApp/start_sis_gateway.php on line 42
用了楼上的代码,不知道为什么报这个错误。

要回复问题请先登录注册