Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between @KafkaListener, @StreamListener and @ServiceActivator?

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?
like image 808
Kamil Zieliński Avatar asked Nov 28 '17 15:11

Kamil Zieliński


1 Answers

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.

like image 159
Oleg Zhurakousky Avatar answered Dec 09 '22 05:12

Oleg Zhurakousky