Using SpringBoot
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
ofspring-kafka
- Version
>= 0.37
ofdev.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:
- Maven
- Gradle
<dependency>
<groupId>dev.responsive</groupId>
<artifactId>responsive-spring</artifactId>
<version>RESPONSIVE_CLIENT_VERSION</version>
</dependency>
implementation 'dev.responsive:responsive-spring:RESPONSIVE_CLIENT_VERSION'
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
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.