简体   繁体   中英

Spring-Kafka vs. kafka-clients directly

I have an application based on spring-boot that needs to consume/produce events on Kafka. I am hesitating on the library choice.

It seems to be simple to use Kafka-clients directly without having to manage the compatibility matrix between spring-Kafka and Kafka-clients:

On the other side, using spring-Kafka helps projects to normalize configuration properties for using Kafka and add embedded kafka for tests.

Are there any other reasons for using spring-Kafka for a spring-boot, instead of using directly kafka-clients ?

Basically, spring-kafka project helps you apply core Spring concepts (dependency injection and declarative) - It provides a "template" as a high-level abstraction for sending messages. - It also provides support for Message-driven POJOs with @KafkaListener annotations and a "listener container".

For people familliar with JMS, you will see similarities to the JMS support in the Spring for the other messaging Framework. If you have spring developers, they will get more confortable using spring-kafka and testing using with Embedded Kafka.

spring-Kafka reduces the technical/redundant code: You achieve the same thing, with less lines of code. - https://docs.spring.io/spring-kafka/reference/html/#even-quicker-with-spring-boot

spring-Kafka helps you control most of Kafka settings through configuration. It simplifies all the errors handling and transaction management.

I have become slightly annoyed at the spring api maybe due to own ignorance, but it seems the spring framework actually prevents certain designs.

I have a situation where I'd like to create a decorator for my consumers that deals with some cross cutting concerns like setting up a logging context based on metadata in the messages I receive.

The @KafkaListener annotation from spring kafka seems to be incompatible with that approach, but I am unsure whether using kafka clients directly would solve the problem.

I do not want to use AOP (AOP is a disease that should be erradicated).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM