Skip to content

在socket被断开的时候,可不可以支持broker的socket断线重连 #49

@djwjiawei

Description

@djwjiawei
  • 你遇到了什么问题?
    在长时间没生产消息时,socket应该有可能会被断开,有没有什么方法去重连被断开的socket;或者后续可不可以支持在config中配置重连次数,在socket发送或接受消息失败后,去重连指定次数socket

  • Kafka 环境是自建还是云服务?
    自建

  • 请执行下面的命令获取环境信息。

php -v & php --ri swoole & composer info | grep longlang/phpkafka

PHP 7.4.19 (cli) (built: May 31 2021 04:55:16) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Yasd v0.3.8, Our Copyright, by codinghuang

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.4.15
Built => May 31 2021 05:59:33
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.0.2k-fips  26 Jan 2017
http2 => enabled
pcre => enabled
zlib => 1.2.7
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? 
longlang/phpkafka                  v1.1.4  A kafka client. Support php-fpm and Swoole.

  • 提供最小可复现代码:
<?php

use longlang\phpkafka\Producer\Producer;
use longlang\phpkafka\Producer\ProducerConfig;

require './vendor/autoload.php';

$config = new ProducerConfig();
$config->setBootstrapServer('192.168.0.252:9092');
$config->setUpdateBrokers(true);

$config->setAcks(-1);
$producer = new Producer($config);
while (true) {
    $producer->send('mq', date('Y-m-d H:i:s'), uniqid('', true));
    sleep(100);
}

拿这个测试了一下,在发送几条消息后,就抛出socket异常了

异常信息:
PHP Fatal error: Uncaught longlang\phpkafka\Exception\SocketException: Unexpected EOF while reading 4 bytes from stream (no data) in /mount/vagrant/learn/es/vendor/longlang/phpkafka/src/Socket/StreamSocket.php:201
Stack trace:
#0 /mount/vagrant/learn/es/vendor/longlang/phpkafka/src/Client/SyncClient.php(164): longlang\phpkafka\Socket\StreamSocket->recv(4)
#1 /mount/vagrant/learn/es/vendor/longlang/phpkafka/src/Producer/Producer.php(153): longlang\phpkafka\Client\SyncClient->recv(3)
#2 /mount/vagrant/learn/es/vendor/longlang/phpkafka/src/Producer/Producer.php(51): longlang\phpkafka\Producer\Producer->sendBatch(Array, 1)
#3 /mount/vagrant/learn/es/prod.php(20): longlang\phpkafka\Producer\Producer->send('mq', '2021-08-18 02:0...', '611c6bbeb61990....')
#4 {main}
thrown in /mount/vagrant/learn/es/vendor/longlang/phpkafka/src/Socket/StreamSocket.php on line 201

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions