Skip to main content

Using SpringBoot

note

This page covers the changes you need to make to support Responsive with Spring Boot. Note that Spring Boot integration currently requires:

  • An application running JDK 17
  • Version 3.3.0 of spring-kafka
  • Version >= 0.37 of dev.responsive.kafka-client

We are working with the spring-kafka maintainer team to lift these requirements. If your team requires a different configuration, please reach out to us at info@responsive.dev.

Usage

Dependencies

In order to use Responsive with spring-kafka, you must include the following dependency:

<dependency>
<groupId>dev.responsive</groupId>
<artifactId>responsive-spring</artifactId>
<version>RESPONSIVE_CLIENT_VERSION</version>
</dependency>

Auto-Wiring

If you use auto-wiring support for spring, replace the @EnableKafkaStreams annotation with @EnableResponsive:

+ import dev.responsive.spring.annotations.EnableResponsive;

@Configuration
@EnableKafka
+ @EnableResponsive
- @EnableKafkaStreams
public class MyKafkaStreamsConfiguration {

@Bean
public KStream<String, String> stream(StreamsBuilder streamsBuiler) {
// this code remains the same
...
}

}

Disabling Autowiring for Cassandra

Spring will attempt to auto-wire Cassandra clients, which are configured by Responsive. You should make sure to disable this by adding the following to your spring boot application:

@SpringBootApplication(exclude = {CassandraDataAutoConfiguration.class, CassandraAutoConfiguration.class})

Manual Configuration

warning

If you are using KafkaStreamsCutsomizer you must manually configure ResponsiveKafkaStreams to avoid overriding the @EnableResponsive annotation. Similarly, if you specify a bean with the name defaultKafkaStreamsBuilder, you should use manual configuration.

In spring-kafka 3.3.0 we introduced a method to the KafkaStreamsCustomizer class that allows you to configure ResponsiveKafkaStreams when customizing your Kafka Streams application:

public class MyStreamsCustomizer extends KafkaStreamsCustomizer {

@Override
public KafkaStreams initKafkaStreams(
Topology topology,
Properties properties,
KafkaClientSupplier clientSupplier
) {
return new ResponsiveKafkaStreams(topology, properties, clientSupplier);
}

...

}

This can be wired into the StreamsBuilderFactoryBean using the #setKafkaStreamsCustomizer method.