From ca58e13fc75159e9772ea87d150ae74f27affa69 Mon Sep 17 00:00:00 2001 From: Soby Chacko Date: Mon, 11 Sep 2023 17:18:42 -0400 Subject: [PATCH] GH-2601: Kafka Streams Binder Docs Cleanup Remove docs references to the deprecated/removed StreamsBuilderFactoryBeanCustomizer in Spring for Apache Kafka in favor of StreamsBuilderFactoryBeanConfigurer. Resolves https://github.com/spring-cloud/spring-cloud-stream/issues/2601 --- .../main/asciidoc/kafka/kafka-streams.adoc | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/src/main/asciidoc/kafka/kafka-streams.adoc b/docs/src/main/asciidoc/kafka/kafka-streams.adoc index a6a7257c3..eb68bbdd1 100644 --- a/docs/src/main/asciidoc/kafka/kafka-streams.adoc +++ b/docs/src/main/asciidoc/kafka/kafka-streams.adoc @@ -1257,35 +1257,33 @@ spring.cloud.stream.kafka.streams.bindings.process-out-0.producer.streamPartitio Each output topic in the application needs to be configured separately like this. -=== StreamsBuilderFactoryBean customizer +=== StreamsBuilderFactoryBean Additional Customizations It is often required to customize the `StreamsBuilderFactoryBean` that creates the `KafkaStreams` objects. Based on the underlying support provided by Spring Kafka, the binder allows you to customize the `StreamsBuilderFactoryBean`. -You can use the `StreamsBuilderFactoryBeanCustomizer` to customize the `StreamsBuilderFactoryBean` itself. -Then, once you get access to the `StreamsBuilderFactoryBean` through this customizer, you can customize the corresponding `KafkaStreams` using `KafkaStreamsCustomzier`. -Both of these customizers are part of the Spring for Apache Kafka project. +You can use the `org.springframework.kafka.config.StreamsBuilderFactoryBeanConfigurer` from Spring for Apache Kafka project to customize/configure the `StreamsBuilderFactoryBean` itself. -Here is an example of using the `StreamsBuilderFactoryBeanCustomizer`. +Here is an example of using the `StreamsBuilderFactoryBeanConfigurer`. ``` @Bean -public StreamsBuilderFactoryBeanCustomizer streamsBuilderFactoryBeanCustomizer() { +public StreamsBuilderFactoryBeanConfigurer streamsBuilderFactoryBeanConfigurer() { return sfb -> sfb.setStateListener((newState, oldState) -> { //Do some action here! }); } ``` -The above is shown as an illustration of the things you can do to customize the `StreamsBuilderFactoryBean`. -You can essentially call any available mutation operations from `StreamsBuilderFactoryBean` to customize it. -This customizer will be invoked by the binder right before the factory bean is started. +The above is shown as an illustration of the things you can do to configure the `StreamsBuilderFactoryBean`. +You can essentially call any available mutation operations from `StreamsBuilderFactoryBean` to configure it. +This configurer will be invoked by the binder right before the factory bean is started. -Once you get access to the `StreamsBuilderFactoryBean`, you can also customize the underlying `KafkaStreams` object. +Once you get access to the `StreamsBuilderFactoryBean`, you can also customize the underlying `KafkaStreams` object via the `KafkaStreamsCustomizer`. Here is a blueprint for doing so. ``` @Bean -public StreamsBuilderFactoryBeanCustomizer streamsBuilderFactoryBeanCustomizer() { +public StreamsBuilderFactoryBeanConfigurer streamsBuilderFactoryBeanConfigurer() { return factoryBean -> { factoryBean.setKafkaStreamsCustomizer(new KafkaStreamsCustomizer() { @Override @@ -1299,9 +1297,9 @@ public StreamsBuilderFactoryBeanCustomizer streamsBuilderFactoryBeanCustomizer() } ``` -`KafkaStreamsCustomizer` will be called by the `StreamsBuilderFactoryBeabn` right before the underlying `KafkaStreams` gets started. +`KafkaStreamsCustomizer` will be called by the `StreamsBuilderFactoryBean` right before the underlying `KafkaStreams` gets started. -There can only be one `StreamsBuilderFactoryBeanCustomizer` in the entire application. +There can only be one `StreamsBuilderFactoryBeanConfigurer` in the entire application. Then how do we account for multiple Kafka Streams processors as each of them are backed up by individual `StreamsBuilderFactoryBean` objects? In that case, if the customization needs to be different for those processors, then the application needs to apply some filter based on the application ID. @@ -1309,7 +1307,7 @@ For e.g, ``` @Bean -public StreamsBuilderFactoryBeanCustomizer streamsBuilderFactoryBeanCustomizer() { +public StreamsBuilderFactoryBeanConfigurer streamsBuilderFactoryBeanConfigurer() { return factoryBean -> { if (factoryBean.getStreamsConfiguration().getProperty(StreamsConfig.APPLICATION_ID_CONFIG)