Home > Software design >  How to connect Kafka to legacy Spring
How to connect Kafka to legacy Spring

Time:10-28

I am working on PoC of connecting legacy Spring application to Kafka. It is war application to be deployed in Tomcat, Spring version 4.3.12. Is there some library to make communication with Kafka almost as easy as with Spring Boot? I need just fundamental operations: sending message, listening for confirmation, receiving.

I have some experience with Spring Boot support as is provided in org.springframework.kafka:spring-kafka library. I am not sure how to efficiently adopt Kafka for legacy Spring - I'm thinking of using Kafka Java client which looks promising but as I am used to working at Spring Boot abstraction level I don't have clue how much code should I supply myself.

Web search is not much helpful in this case since it tends to show Spring Boot-related solutions. Migration of legacy application is considered too, I just need to have some idea how difficult each way is.

CodePudding user response:

kafka-clients is all you need (from Maven Central, not Confluent). You could go a step further and look into Log4j2 Kafka bridge, then property files for that.

If you want to externalize config into regular Java .properties file, you can, or you can pull values from environment variables, if you follow 12-factor principles.

But if you don't already have Spring Boot dependencies, then I do not think adding them is worth it for only Kafka.

Also, the Spring-Kafka documentation covers how to configure your app without Boot.

  • Related