多个gatewayworker里同时设置指定的businessworker?

zhuyujin001

问题描述

这里写问题描述
3个websocket,如何让每一个Gateway的数据怎么定指定到哪个businessworker上来处理啊,在webman的config文件夹里怎么配置啊?
比如chatmsg的Gateway 指定到 'eventHandler' => common\sockets\ChatEvents::class,
notice的的Gateway 指定到 'eventHandler' => common\sockets\NoticeEvents::class,
channel的Gateway 指定到 'eventHandler' => common\sockets\ChannelEvents::class,
在webman的config文件夹里怎么配置啊?

return [
     // msg 用于聊天
    'chatmsg' => [
        'handler'     => Gateway::class,
        'listen'      => 'websocket://0.0.0.0:7272',
        'count'       => 1,
        'reloadable'  => false,
        'constructor' => ['config' => [
            'lanIp'           => '127.0.0.1',
            'startPort'       => 2300,
            'pingInterval'    => 20,
            'pingData'        => '{"type":"ping"}',
            'registerAddress' => '127.0.0.1:1236',
            'onConnect'       => function(){},
        ]]
    ], 
    // notice 新订单和新退款单 消息通知
   'notice' => [
        'handler'     => Gateway::class,
        'listen'      => 'websocket://0.0.0.0:7273',
        'count'       => 1,
        'reloadable'  => false,
        'constructor' => ['config' => [
            'lanIp'           => '127.0.0.1',
            'startPort'       => 2300,
            'pingInterval'    => 20,
            'pingData'        => '{"type":"ping"}',
            'registerAddress' => '127.0.0.1:1236',
            'onConnect'       => function(){},
        ]]
    ],         
    // 系统程序接收到发送过来的消息
    'channel' => [
        'handler'     => Gateway::class,
        'listen'      => 'frame://0.0.0.0:7274',
        'count'       => 1,
        'reloadable'  => false,
        'constructor' => ['config' => [
            'lanIp'           => '127.0.0.1',
            'startPort'       => 2300,
            'pingInterval'    => 20,
            'pingData'        => '{"type":"ping"}',
            'registerAddress' => '127.0.0.1:1236',
            'onConnect'       => function(){},
        ]]
    ], 

    'businesser' => [
        'handler'     => BusinessWorker::class,
        'count'       => cpu_count()*2,
        'constructor' => ['config' => [
            //'eventHandler'    => plugin\webman\gateway\Events::class,
            'eventHandler'    => common\sockets\ChatEvents::class,
            'name'            => 'ChatBusinessWorker',
            'registerAddress' => '127.0.0.1:1236',
        ]]
    ],
    'register' => [
        'handler'     => Register::class,
        'listen'      => 'text://127.0.0.1:1236',
        'count'       => 1, // Must be 1
        'constructor' => []
    ],
];
160 1 0
1个回答

walkor 打赏

同一个gatewayWorker里不能分别指定eventHandler。
在Events.php里统一接收,让然后根据$_SERVER['GATEWAY_PORT']区分端口,手动调用不同的类

×
🔝