RT:
我這樣設(shè)置了兩個businessworker,兩個一個$worker->eventHandler ='Events_SIS';一個默認,但是Gateway的數(shù)據(jù)怎么定指定到哪個businessworker,上來處理?。?img src="http://m.wtbis.cn/upload/20191123/235dd8bc85b3bf.png" alt="" />
設(shè)置兩個businessworker是可以運行,但是不知道怎么指定gateway的消息到其中的一個Gateway.
方法就是樓上說的為gateway設(shè)置路由,主要是 $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];
};
Notice: Undefined index: 127.0.0.1:BusinessWorker_SIS:0 in /var/www/html/GatewayWorker/Applications/YourApp/start_sis_gateway.php on line 42
用了樓上的代碼,不知道為什么報這個錯誤。
$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發(fā)現(xiàn)沒有錯,經(jīng)檢查是因為0打了單引號。
初次寫代碼,不懂不好意思。