getting unable to resolve class KafkaConsumer
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();
Can u try with fully qualified name of KafkaConsumer?
could you provide full code or file and can you explain where i need to put this code
add this at top: import org.apache.kafka.clients.consumer.*;
Do you still face the issue or is it resolved?
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?
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
You need to convert your kafkaParam map to a Java collection using asJava function. You need to import collection.JavaConverters._ in your program
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.*;