Method Level @KafkaListener
Selection Criteria
Found method will be selected for further processing only if:
It has @KafkaListener annotation on one of its methods and has valid arguments.
Registration process
Operations registration process depends on @SendTo annotation usage.
With @SendTo
See Receive & Reply Operations
Without @SendTo
When listener is registered without @SendTo annotation, one-to-one operation will be created for each @KafkaListener annotation.
java
@Component
public class MultiMessagesListener {
@KafkaListener(topics = {"messages.blue"})
@KafkaListener(topics = {"messages.green", "messages.yellow"}, groupId = "group-id")
public void listen(Object message) {}
}The next operations will be created:
- receive
Objectfrommessages.blue - receive
Objectfrommessages.greenwith groupIdgroup-id - receive
Objectfrommessages.yellowwith groupIdgroup-id
When method will be ignored?
Here are the examples of methods which will be ignored:
Method with empty @KafkaListener annotation
This class will be ignored because it has empty @KafkaListener annotation.
java
@Component
public class MultiMessagesListener {
@KafkaListener
public void listen(Object message) {}
}