workerman reload 重启 遇到Channel不能正常工作问题

美丽的角落

问题描述

workerman reload

本人使用的是Events事件静态回调,在OnWorkerStart集合了Channel服务connect(),reload重启workerman,进程什么的也依次拉起,channel也经过两次try connect进行拉起,但是就接收数据而言,OnMessage 依然接收正常,而channel不管是用订阅还是队列,都不能发送与消费,除非客户端重新建立链接。
求问各位有没有相关的解决方案,拜谢!

程序代码

public static function onWorkerStart(BusinessWorker $businessWorker)
    {
                    ChannelClient::connect(config('wk.channel.ip'),config('wk.channel.port'));
        self::TimerWorker($businessWorker);
    }

public static function onMessage(string $clientId,  $messageJson)
{
       // 队列
        ChannelClient::enqueue(self::$queue.$clientId, $messageJson);
        // 订阅
        // ChannelClient::publish(self::$queue.$clientId, $messageJson);
    }

 public static function onWebSocketConnect(string $clientId, $data)
    {
        $query_string = $data['server']['QUERY_STRING'];
        $data = self::checkParamsURI($query_string);
        if(empty($query_string) || empty($data['params']['sn']))
        {
            Gateway::closeClient($clientId);
            return false;
        }

        Gateway::bindUid($clientId, $data['params']['sn']);
        $_SESSION[$clientId] = $data['params']['sn'];

        $yun = config('stt_cn.STT_CN.wsUri').'?'.$data['query_string'];
        $ws_connection = new AsyncTcpConnection($yun);
        $ws_connection->WebsocketPingInterval = 10;
        $ws_connection->websocketType = Websocket::BINARY_TYPE_ARRAYBUFFER;//BINARY_TYPE_ARRAYBUFFER BINARY_TYPE_BLOB
        $ws_connection->onConnect = function($connection){
            // $connection->keepConnection = true;
        };
        $ws_connection->onWebSocketConnect = function(AsyncTcpConnection $con, $responce) use($clientId){

            $event_name = self::$queue.$clientId;
            ChannelClient::watch($event_name, function($data) use ($clientId, $con) {
                $con->send($data);
            });
        };
        $ws_connection->onMessage = function($connection, $data) use($clientId){

            self::sendMessage( $data, $clientId);
        };
        $ws_connection->onError = function($connection, $code, $msg) use($clientId){

            self::log(__FUNCTION__, $code, $msg);
        };
        $ws_connection->onClose = function($connection) use($clientId){

        };
        $ws_connection->connect();
        // self::$ws_server = $ws_connection;

    }
344 1 0
1个回答

walkor 打赏

这个要自己详细打日志,别人没环境帮不上

  • 暂无评论
×
🔝