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

0

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

已邀请:

喵了个咪

赞同来自:

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

blogdaren - 常年游走于 Linux、PHP、C、VIM 之间【http://www.phpcreeper.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
用了楼上的代码,不知道为什么报这个错误。

veinliu - 编程新人

赞同来自:

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

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

// var_dump( $worker_connections);
return $worker_connections[$client_connection->businessworker_address];
};

二楼的代码非常正确,只不过我的情况只有一个worker 所以ID 是0,然后我改成零不能用,后来var_dump发现没有错,经检查是因为0打了单引号。
初次写代码,不懂不好意思。

要回复问题请先登录注册