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

一个消费者组下两个消费者,只有一个能消费消息 #52

Closed
RickLwy opened this issue Sep 2, 2021 · 4 comments
Closed
Labels
question Further information is requested

Comments

@RickLwy
Copy link

RickLwy commented Sep 2, 2021

  • 你遇到了什么问题?

一个消费者组下两个消费者,只有一个能消费消息

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

docker自建

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

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

# 粘贴到这里
[1] 15367
[2] 15368
Extension 'swoole' not present.
PHP 7.3.0beta1 (cli) (built: Mar 12 2020 12:13:45) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
Do not run Composer as root/super user! See https://getcomposer.org/root for details
longlang/phpkafka          v1.1.5 A kafka client. Support php-fpm and Swoole.
[1]-  完成                  php -v
[2]+  退出 1                php --ri swoole

  • 提供最小可复现代码:
// 你的代码
use longlang\phpkafka\Consumer\ConsumeMessage;
use longlang\phpkafka\Consumer\Consumer;
use longlang\phpkafka\Consumer\ConsumerConfig;
function consume(ConsumeMessage $message)
{
    var_dump($message->getKey() . ':' . $message->getValue());
    // $consumer->ack($message); // autoCommit设为false时,手动提交
}

$rand = rand(1000,9999);

$config = new ConsumerConfig();
$config->setBroker('192.168.1.166:32769');
$config->setTopic('test'); // 主题名称
$config->setGroupId('testGroup'); // 分组ID
$config->setClientId($rand); // 客户端ID,不同的消费者进程请使用不同的设置
$config->setGroupInstanceId($rand); // 分组实例ID,不同的消费者进程请使用不同的设置
$config->setInterval(0.1);
$consumer = new Consumer($config, 'consume');
$consumer->start();
@Yurunsoft
Copy link
Member

等一会会自动触发rejoin,默认应该是60秒,那时候就可以消费到了

@RickLwy
Copy link
Author

RickLwy commented Sep 2, 2021

image
image
等了10分钟,还是只有一个消费者可以接收到消息,帮我看下是不是我配置的问题,谢谢
image

@Yurunsoft
Copy link
Member

我复制的你的代码,两个都可以消费,只不过有一个消费的数量比较少,这个是正常的,分配算法原因
image

@Yurunsoft Yurunsoft added the question Further information is requested label Sep 2, 2021
@RickLwy
Copy link
Author

RickLwy commented Sep 2, 2021

代码没有问题,是我kafka分区数量的问题,谢谢大佬

@RickLwy RickLwy closed this as completed Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants