简体   繁体   English

超时读取Kafka集群设置的套接字错误

[英]Getting Timed out reading socket error for kafka cluster setup

I want to setup a kafka cluster type setup for three similar application having same queues like AppA -> {TopicX, TopicY, TopicZ}, AppB -> {TopicX, TopicZ}, AppC -> {TopicX, TopicY}. 我想为三个相似的应用程序(具有相同的队列,如AppA-> {TopicX,TopicY,TopicZ},AppB-> {TopicX,TopicZ},AppC-> {TopicX,TopicY})设置kafka群集类型设置。 Producer and Consumer will be App specific. 生产者和消费者将特定于应用程序。 I setup kafka cluster with three brokers having partition 1,2,3 in three different config files with different ports. 我用三个具有不同端口的不同配置文件中的分区1,2,3的三个代理设置了kafka集群。 Then start kafka server ( cluster ) 然后启动kafka服务器(集群)

I am using kafka php wrapper by http://github.com/nmred/kafka-php 我正在使用http://github.com/nmred/kafka-php的 kafka php包装器

So I used Producer code for App A like 所以我使用App A的Producer代码

       $producer->setRequireAck(-1);
       $producer->setMessages("TopicX", 0, array(json_encode($this->data)));
       $producer->send();

AND used Producer code for App B like 并且使用App B的生产者代码,例如

       $producer->setRequireAck(-1);
       $producer->setMessages("TopicX", 1, array(json_encode($this->data)));
       $producer->send();

And So On. 等等。

Then I made my Consumer scripts for three apps like 然后,我为三个应用制作了Consumer脚本,例如

        $queues = array("TopicX", "TopicY", "TopicZ");
        while(true) {
            foreach($queues as $queue) {
                $consumer = \Kafka\Consumer::getInstance('localhost:2181');
                $consumer->setGroup('testgroup');
                $consumer->setPartition($queue, 0);
                $result = $consumer->fetch();
           }
        }

But when I try to execute consumer script for any App I get error like 但是,当我尝试为任何应用执行使用者脚本时,都会收到类似

"Timed out reading socket while reading 750437 bytes with 750323 bytes to go" “在读取750437字节和750323字节时读取套接字超时”

I just don't know How I can fix this issue I tried to modify some kafka config parameters like 我只是不知道如何解决此问题,我试图修改一些kafka配置参数,例如

 zookeeper.connection.timeout.ms=24000         # Initially 6000
 replica.socket.timeout.ms=15000                      # Not exists in default file

but that not worked. 但这没用。

You're actually destroying the Kafka consumer by declaring it into your foreach cycle, move it out of the cycle, use the cycle to set the partitions and then fetch the results and discriminate between the sources: 您实际上是通过将其声明为foreach周期来销毁Kafka使用者,将其移出该循环,使用该循环设置分区,然后获取结果并对源进行区分:

$queues = array("TopicX", "TopicY", "TopicZ");
$consumer = \Kafka\Consumer::getInstance('localhost:2181');
$consumer->setGroup('testgroup');

foreach($queues as $queue) {
  $consumer->setPartition($queue, 0);
}

while(true) {
  $result = $consumer->fetch();
  foreach ($result as $topicName => $topic) {
    foreach ($topic as $partId => $partition) {
      var_dump($partition->getHighOffset());
      foreach ($partition as $message) {
        var_dump((string)$message);
      }
    }
  }
}

See the github README of the kafka php project to see an example. 请参阅kafka php项目的github自述文件,以查看示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM