Hello all, i am trying to integrate kafka in our project , the project is in java (not in spring boot), Unlike Spring boot , as i understood we can consume based on the events. How can i achieve the same in java without using springboot,
As of now i implemented poll based mechanism, But i want , the consumer should only poll when there is a new message on the topic.
in Spring boot , where it works perfectly fine
@KafkaListener(topics = “${avro.topic.name}”, containerFactory = “kafkaListenerContainerFactory”, groupId = “foo”)
public void read(ConsumerRecord<String, FxAlarm> record,@Header(KafkaHeaders.RECEIVED_PARTITION_ID) int partition){
in java w/o spring boot
while (true) {
ConsumerRecords<Integer, Alarm> records = consumer.poll(Duration.ofMillis(200));
for(ConsumerRecord record: records) {
System.out.println("Received new record " + "key: "+ record.key()+"value: " + record.value()+ "topicname: "+ record.topic() + "partition id : " + record.partition() );
}
}
So whats the best way to avoid polling on a time interval , instead pull only when there is a event/message in topic