I have the following problem. I want to start a spring boot application which reads and writes from kafka using @KafkaListener.
I want to:
- initialise the kafka consumer to the latest offset.
- write messages to kafka
- then read those messages back from kafka, using the consumer created in step 1
I am facing the following problem Step 2 is sometimes running before the kafka consumer has had time to do the first poll() operation. This means that it then ignores these messages because it considers them before latest.
Is there anyway when using spring-kafka to ensure that the consumers poll before the application starts up.
KafkaTemplate
to send synchronously, meaning that the send will block until the message has been sent. E.g.kafkaTemplate.send("key", "value").get()
. The.send(..)
return aFuture
which you can block by calling.get().
– kkflf