Webman中有两个gateway ,Gateway::sendToUid()有时发送不成功

zyyzcr

问题描述

webman中开启了两个gateway,对应的register分别为:127.0.0.1:6238和127.0.0.1:7238

当用下面的方法发送消息时,客户端有时收不到消息,也看不到报错信息(gateway-worker 版本 v3.1.0 )

Gateway::$registerAddress="127.0.0.1:7238";
Gateway::sendToUid("client1", json_encode($message));

770 1 0
1个回答

walkor 打赏

可能你哪里配置错了,尤其是registerAddress

  • zyyzcr 2023-11-09

    检查了下registerAddress好像没问题

    <?php
    
    use Webman\GatewayWorker\Gateway;
    use Webman\GatewayWorker\BusinessWorker;
    use Webman\GatewayWorker\Register;
    
    return [
        'gateway_ws' => [
            'handler'     => Gateway::class,
            'listen'      => 'websocket://0.0.0.0:6272',
            'count'       => cpu_count(),
            'reloadable'  => false,
            'constructor' => ['config' => [
                'lanIp'           => '127.0.0.1',
                'startPort'       => 2300,
                'pingInterval'    => 25,
                'pingNotResponseLimit'    => 0,
                'pingData'        => '{"type":"ping"}',
                'registerAddress' => '127.0.0.1:6238',
                'onConnect'       => function(){},
            ]]
        ],
        'gateway_tcp' => [
            'handler'     => Gateway::class,
            'listen'      => 'tcp://0.0.0.0:6282',
            'count'       => cpu_count(),
            'reloadable'  => false,
            'constructor' => ['config' => [
                'lanIp'           => '127.0.0.1',
                'startPort'       => 2310,
                'pingInterval'    => 25,
                'pingNotResponseLimit'    => 0,
                'pingData'        => '{"type":"ping"}',
                'registerAddress' => '127.0.0.1:6238',
                'onConnect'       => function(){},
            ]]
        ],
        'worker' => [
            'handler'     => BusinessWorker::class,
            'count'       => cpu_count()*1,
            'constructor' => ['config' => [
                'eventHandler'    => plugin\webman\zy_videostream\Events::class,
                'name'            => 'ChatBusinessWorker',
                'registerAddress' => '127.0.0.1:6238',
            ]]
        ],
        'register' => [
            'handler'     => Register::class,
            'listen'      => 'text://0.0.0.0:6238',
            'count'       => 1, // Must be 1
            'constructor' => []
        ],
    ];
    <?php
    
    use Webman\GatewayWorker\Gateway;
    use Webman\GatewayWorker\BusinessWorker;
    use Webman\GatewayWorker\Register;
    
    return [
        'gateway_ws' => [
            'handler'     => Gateway::class,
            'listen'      => 'websocket://0.0.0.0:7272',
            'count'       => cpu_count(),
            'reloadable'  => false,
            'constructor' => ['config' => [
                'lanIp'           => '127.0.0.1',
                'startPort'       => 2400,
                'pingInterval'    => 3,
                'pingNotResponseLimit'    => 0,
                'pingData'        => '{"code":"ping"}',
                'registerAddress' => '127.0.0.1:7238',
                'onConnect'       => function(){},
            ]]
        ],
        'gateway_tcp' => [
            'handler'     => Gateway::class,
            'listen'      => 'tcp://0.0.0.0:7282',
            'count'       => cpu_count(),
            'reloadable'  => false,
            'constructor' => ['config' => [
                'lanIp'           => '127.0.0.1',
                'startPort'       => 2410,
                'pingInterval'    => 3,
                'pingNotResponseLimit'    => 0,
                'pingData'        => '{"code":"ping"}',
                'registerAddress' => '127.0.0.1:7238',
                'onConnect'       => function(){},
            ]]
        ],
        'worker' => [
            'handler'     => BusinessWorker::class,
            'count'       => cpu_count()*1,
            'constructor' => ['config' => [
                'eventHandler'    => plugin\webman\zy_fzb\Events::class,
                'name'            => 'FzbBusinessWorker',
                'registerAddress' => '127.0.0.1:7238',
            ]]
        ],
        'register' => [
            'handler'     => Register::class,
            'listen'      => 'text://0.0.0.0:7238',
            'count'       => 1, // Must be 1
            'constructor' => []
        ],
    ];
  • walkor 2023-11-09

    配置没问题的话可能是逻辑哪里有问题,比如连接没绑定uid或者连接已经断开或者uid是错的等等,其它人没办法给你排查,需要自己定位下

  • zyyzcr 2023-11-09

    好的,谢谢

  • zyyzcr 2023-11-09

    已解决
    添加Gateway::$addressesCacheDisable=true;就可以了

  • 清梦独行 2023-12-04

    在哪里配置的Gateway::$addressesCacheDisable=true

  • fantasmic 2023-12-06

    同问,在有2个Gateway配置的情况下,AB分别连2个Gateway端口,getAllUidList时只能获得其中一个

年代过于久远,无法发表回答
×
🔝