I'm new in Spring-Kafka, I created a class that is called KafkaListeners to read messages from kafka broker. However, the listener didn't print old messages in console. So, I added @TopicPartition annotation on my listener method. But, I encountered an error message as follows:
An annotation can't be used as the annotations argument
Script:
@KafkaListener(
topicPartitions = @TopicPartition(topic = "demo",
partitionOffsets = {
@PartitionOffset(partition = "0", initialOffset = "0")
}
)
)
fun listenerDemo(data: Any?){
println(data)
}
As Image :
I saw @TopicPartition usage in java and it is running but it isn't in kotlin.
Thank you.
CodePudding user response:
The Kotlin configuration has to be like this:
@KafkaListener(
topicPartitions = [TopicPartition(topic = "demo",
partitionOffsets =
[PartitionOffset(partition = "0", initialOffset = "0")]
)]
)
Those nested annotations must be without @
and since those attributes are arrays, we have to specify these nested annotations as arrays as well.