Spring for Apache Kafka

The Spring for Apache Kafka (spring-kafka) project applies core Spring concepts to the development of Kafka-based messaging solutions. 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". These libraries promote the use of dependency injection and declarative. In all of these cases, you will see similarities to the JMS support in the Spring Framework and RabbitMQ support in Spring AMQP.

Features

  • KafkaTemplate

  • KafkaMessageListenerContainer

  • @KafkaListener

  • KafkaTransactionManager

  • spring-kafka-test jar with embedded kafka server

Kafka Client Compatibility

Spring for Apache Kafka is based on the pure java kafka-clients jar. The following is the compatibility matrix:

Spring for Apache Kafka Version

Spring Integration for Apache Kafka Version

kafka-clients

2.2.x

3.1.x

2.0.0, 2.1.0

2.1.x

3.0.x

1.0.x, 1.1.x, 2.0.0

2.0.x

3.0.x

0.11.0.x, 1.0.x

1.3.x

2.3.x

0.11.0.x, 1.0.x

1.2.x

2.2.x

0.10.2.x

1.1.x

2.1.x

0.10.0.x, 0.10.1.x

1.0.x

2.0.x

0.9.x.x

N/A*

1.3.x

0.8.2.2

IMPORTANT: This matrix is client compatibility; in most cases (since 0.10.2.0) newer clients can communicate with older brokers. All users with brokers >= 0.10.x.x (and all spring boot 1.5.x users) are recommended to use spring-kafka version 1.3.x or higher due to its simpler threading model thanks to KIP-62. For a complete discussion about client/broker compatibility, see the Kafka Compatibility Matrix

  • Spring Integration Kafka versions prior to 2.0 pre-dated the Spring for Apache Kafka project and therefore were not based on it.

These versions will be referenced transitively when using maven or gradle for version management. For the 1.1.x version, the 0.10.1.x is the default.

2.1.x uses the 1.1.x kafka-clients by default. When overriding the kafka-clients for 2.1.x see the documentation appendix.

2.2.x uses the 2.0.x kafka-clients by default. When overriding the kafka-clients for 2.2.x see the documentation appendix.

  • Spring Boot 1.5 users should use 1.3.x (Boot dependency management will use 1.1.x by default so this should be overridden).

  • Spring Boot 2.0 users should use 2.0.x (Boot dependency management will use the correct version).

  • Spring Boot 2.1 users should use 2.2.x (Boot dependency management will use the correct version).

Quick start

Bootstrap your application with Spring Initializr.

Documentation

Each Spring project has its own; it explains in great details how you can use project features and what you can achieve with them.
2.2.3 SNAPSHOT Reference Doc. API Doc.
2.2.2 GA Reference Doc. API Doc.
2.1.12 SNAPSHOT Reference Doc. API Doc.
2.1.11 GA Reference Doc. API Doc.
1.3.9 SNAPSHOT Reference Doc. API Doc.
1.3.8 GA Reference Doc. API Doc.

A few examples to try out: