1

I am trying to setup a kafka consumer on legacy web application using xml configuration that is running Spring 5.2 release project (It is not a spring boot project). After looking up I found a project that sets up the kafka consumer using xml configuration like in here

https://docs.spring.io/spring-kafka/docs/1.3.11.RELEASE/reference/html/_spring_integration.html

However this does not give details on how to connect this with java in a spring web application . All examples are for spring-boot project. I did find out what configuring I need to add to xml

https://github.com/spring-projects/spring-integration-kafka

I also did find an example of Spring web application and kafka but it is for 4.X release and is from 2015.

https://techannotation.wordpress.com/2015/10/26/introduction-to-apache-kafka-using-spring/

Any help on any newer documentation or on how to setup a consumer in java spring web project with xml configuration in 2020 would be appreciated

Praveen
  • 557
  • 1
  • 5
  • 20

2 Answers2

1

With Help from Gary Russel and Artem Bilan I was able to figure this out. Since I am using legacy spring application I needed this project and not spring integration project

https://spring.io/projects/spring-kafka

I also followed documentation here to setup java config for kafka listener

https://docs.spring.io/spring-kafka/docs/2.3.12.RELEASE/reference/html/#with-java-configuration

I used this to figure out how to have both java config and xml config work together

https://memorynotfound.com/mixing-xml-java-config-spring/

Here is gist of my implementation that worked

https://gist.github.com/praveen2710/7dcf1671379ee6db4581436e1225c673

Praveen
  • 557
  • 1
  • 5
  • 20
0

It is not clear why you mention Spring Integration framework all the time, but you don't accent on it. Let's see if this doc helps you though: https://docs.spring.io/spring-integration/docs/current/reference/html/kafka.html#kafka !

Pay attention the Spring Integration is 5.4 already.

This sample is Spring Boot based, but still should give you a general idea how to configure Kafka channel adapter with Java: https://github.com/spring-projects/spring-integration-samples/tree/master/basic/kafka

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • I guess I should have mentioned it is a legacy spring web application that does not use spring-boot starter – Praveen Nov 09 '20 at 15:06
  • That's OK. You still can use Spring Kafka and Spring Integration. Only the problem that you need to follow the latest versions instructions. I'm not sure what Spring 5.2 you mean, but if you are with Spring Integration, you really should take that `spring-integration-kafka` and its latest features. – Artem Bilan Nov 09 '20 at 15:11
  • Are you using Spring Integration at all? If not, you only need spring-kafka. https://spring.io/projects/spring-kafka – Gary Russell Nov 09 '20 at 15:17
  • I dont think I use spring integration since use spring framework dependencies directly. This is quite an old service that I am trying to set a kafka consumer on. It does not even use java configuration but uses old web xml style configuration. – Praveen Nov 09 '20 at 15:22
  • OK. So, follow, please, the link Gary suggests. – Artem Bilan Nov 09 '20 at 15:27
  • @GaryRussell Might sound silly but do you by any chance have an example of setting this in .spring.xml . I followed the steps but it looks like I cannot have both spring and java configuration at same time – Praveen Nov 09 '20 at 15:55
  • You can. See an `@ImportResource` from Spring Framework: https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-java-combining – Artem Bilan Nov 09 '20 at 15:57