7

I want to use Kafka with Spring Boot and with Avro schemas. But I'm stucked on 'What is the difference between those 3 listeners?'. There are 3 possibilities to create listeners: annotate a method with - @KafkaListener, @StreamListener or @ServiceActivator. Seems like all of them are listening for incoming events but I cannot see/find difference between those solutions.

  1. What is the difference between those three?
  2. What are prons and cons of each solution?
  3. Which fits more for purpose of using Avro?
Gary Russell
  • 166,535
  • 14
  • 146
  • 179
Kamil Zieliński
  • 357
  • 6
  • 13

1 Answers1

12

So, I'll start with @KafkaListener. That one is simple as it is coming from "spring-kafka" project and can be used outside of Spring Cloud Stream.

The @ServiceActivator is coming from "spring-integraton" project and similarly to @KafkaListener can be used outside of Spring Cloud Stream.

Both can also be used inside of Spring Cloud Stream application - primarily for convenience.

The @StreamListener is the only one that is native to Spring Cloud Stream.

For simple cases you can make your pick. For more complex cases see the extra capabilities of a particular annotation. For example, you can define conditions when using @StreamListener.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
Oleg Zhurakousky
  • 5,820
  • 16
  • 17