Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于消息发送和接收的稳定性优化 #5

Closed
billlv opened this issue Dec 10, 2022 · 1 comment
Closed

关于消息发送和接收的稳定性优化 #5

billlv opened this issue Dec 10, 2022 · 1 comment

Comments

@billlv
Copy link

billlv commented Dec 10, 2022

推送:sync_publish(Builder::instance(), $params, null, true); 说明文档中,最后的close 参数,最好默认是true。 如果该方法应用在 controller 部分,这个会因为没有固定的 心跳监听而造成大量的发布失败。 虽然每次都会重新创建连接,那也是稳定和高效的。

process 里的消息接收。建议加入重连检查。有时候网络断开造成的消费者丢失没有重连。 或者搞个重连开关。

`
public function onWorkerStart(Worker $worker): void
{
parent::onWorkerStart($worker);

    Timer::add(10, function () {
        $this->checkConnection();
    });

}

private function checkConnection() {
    try {
        if($this->connection()->client()->isConnected() == false) {
            $this->logger->debug('Reconnect');
            $this->connection()->consume($this->getMessage());
        }else {
            $this->logger->debug('Connection is OK');
        }
    } catch (\Exception $e) {
        $this->logger->error($e->getMessage());
    }
}

`

@chaz6chez
Copy link
Member

  1. 生产者原本的功能意义主要是为了短时间不去重复创建连接,而不是为了保持进程长连接;我们会在下个版本增加心跳检测,从而满足进程内的长连接客户端维持;
  2. 消费者的异步客户端在触发消费时,如果客户端报错则会进入重连状态,重连方式是将当前进程重启,消息不会丢失,也没有ack,在进程重启后会正常消费;详见AsyncClient.php中101行。唯一的不足是主程序stop后,消费进程onWorkerStop中触发的close是异步执行的,等不到执行,eventloop就被销毁,导致rabbitMQ服务端会有warning错误日志,这是workerman底层机制的问题,实际使用不影响正常业务;这个问题我们也会在后续版本完善处理。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants