Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

kafka network Processor error in producer program(ArrayIndexOutOfBoundsException: 18)

I have below kafka producer Api program and i am new to kafka itself. Below code fetch data from one of API and send message to kafka topic.

package kafka_Demo;

import java.util.Properties;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.apache.kafka.clients.producer.*;
import java.net.URL;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;

public class HttpBasicAuth {

    public static void main(String[] args) {
        try {

            Properties props = new Properties();
             props.put("bootstrap.servers", "localhost:9092");
             props.put("zookeeper.connect", "localhost:2181");
             props.put("batch.size", 16384);
             props.put("linger.ms", 1);
             props.put("buffer.memory", 33554432);
             props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
             props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

            Producer<String, String> producer = new KafkaProducer<>(props);
            Json_read count = new Json_read();
            URL url = new URL("https://alm.sysbiz.org/rest/api/2/search?jql=project=ALG&maxResults=0");
            long total_ticket = count.ticketCount(url);
            Alm_authentication alm = new Alm_authentication();
            for (long i = 0; i <=total_ticket ; i = i + 20) {
                url = new URL("https://alm.sysbiz.org/rest/api/2/search?jql=project=ALG&expand=changelog&startAt=" + i+"&maxResults=20");
                InputStream content = (InputStream) alm.performAuth(url);
                if (content != null) {
                    BufferedReader in = new BufferedReader(new InputStreamReader(content));
                    String line;
                    while ((line = in.readLine()) != null) {
                        //writer.println(line);
                        // System.out.println(line);
                        producer.send(new ProducerRecord<String, String>("test", "a11", line)).get();
                    }               
                }
                producer.send(new ProducerRecord<String, String>("test", "a11", "\n"));
                content.close();

            }

         producer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }


    }

}

While i am running above code i am getting below error at kafka broker.

ERROR Processor got uncaught exception. (kafka.network.Processor)
java.lang.ArrayIndexOutOfBoundsException: 18
    at org.apache.kafka.common.protocol.ApiKeys.forId(ApiKeys.java:68)
    at org.apache.kafka.common.requests.AbstractRequest.getRequest(AbstractRequest.java:39)
    at kafka.network.RequestChannel$Request.<init>(RequestChannel.scala:79)
    at kafka.network.Processor$$anonfun$run$11.apply(SocketServer.scala:426)
    at kafka.network.Processor$$anonfun$run$11.apply(SocketServer.scala:421)
    at scala.collection.Iterator$class.foreach(Iterator.scala:727)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at kafka.network.Processor.run(SocketServer.scala:421)
    at java.lang.Thread.run(Thread.java:748)

I have tried a lot by searching in Google but no luck. Can any one help me to resolve it. And below error i can see it in my eclipse IDE.

java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
    at org.apache.kafka.clients.producer.KafkaProducer$FutureFailure.<init>(KafkaProducer.java:1124)
    at org.apache.kafka.clients.producer.KafkaProducer.doSend(KafkaProducer.java:823)
    at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:760)
    at org.apache.kafka.clients.producer.KafkaProducer.send(KafkaProducer.java:648)
    at kafka_Demo.HttpBasicAuth.main(HttpBasicAuth.java:40)
Caused by: org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.  
like image 971
Tharunkumar Reddy Avatar asked Jan 28 '23 15:01

Tharunkumar Reddy


1 Answers

This happens due to kafka version mismatch. Make sure kafka-clients jar version & kafka server version installed in your machine.

like image 50
Prasath Avatar answered Feb 06 '23 14:02

Prasath