pepper-box icon indicating copy to clipboard operation
pepper-box copied to clipboard

getting unable to resolve class KafkaConsumer

Open Gleesha opened this issue 7 years ago • 8 comments

I am getting an error "unable to resolve class KafkaConsumer" when running a groovy script in JSR223 Sampler. Below is the script for reference. Please suggest what can be the possible solution for this. Also, if possible please provide jar for com.gslab.pepper.Message

Properties props = new Properties(); props.put("bootstrap.servers", "localhost:9092"); props.put("group.id", group); props.put("enable.auto.commit", "true"); props.put("auto.commit.interval.ms", "1000"); props.put("session.timeout.ms", "30000"); props.put("key.deserializer",
"org.apache.kafka.common.serializa-tion.StringDeserializer"); props.put("value.deserializer", "org.apache.kafka.common.serializa-tion.StringDeserializer"); KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(props);

  consumer.subscribe(Arrays.asList(topic));

long t = System.currentTimeMillis(); long end = t + 5000; f = new FileOutputStream(".\data.csv", true); p = new PrintStream(f); while (System.currentTimeMillis()<end) { ConsumerRecords<String, String> records = consumer.poll(100); for (ConsumerRecord<String, String> record : records) { p.println( "offset = " + record.offset() +" value = " + record.value()); } consumer.commitSync();
} consumer.close(); p.close(); f.close();

Gleesha avatar Apr 01 '18 14:04 Gleesha

Can u try with fully qualified name of KafkaConsumer?

satishbhor avatar Apr 05 '18 06:04 satishbhor

could you provide full code or file and can you explain where i need to put this code

guptamohit09 avatar Aug 23 '18 05:08 guptamohit09

add this at top: import org.apache.kafka.clients.consumer.*;

BILJ65 avatar Oct 04 '18 18:10 BILJ65

Do you still face the issue or is it resolved?

Nachiket90 avatar Jan 30 '19 06:01 Nachiket90

I also encountered the same problem. I guess I can't find the class KafkaConsumer, but I'm a novice in java. How can I solve it?

Verckolf avatar Apr 03 '19 11:04 Verckolf

I have te same problem, can not find that class. I get this: The type KafkaConsumer is not generic; it cannot be parameterized with arguments <Long, String> Im working in SpringBoot 2.2.0.M2 using java 8

aresares avatar May 01 '19 15:05 aresares

You need to convert your kafkaParam map to a Java collection using asJava function. You need to import collection.JavaConverters._ in your program

Hrshvrdhn avatar Feb 07 '20 12:02 Hrshvrdhn

I had the same problema here and solved it with following add import lines:

import java.util.Properties; import java.util.Arrays; import org.apache.kafka.clients.consumer.*;

daviribeiro avatar Sep 14 '20 15:09 daviribeiro