From 52e506ec76bd3484378298b8a758b00e50081f44 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 27 Nov 2023 09:35:26 -0500 Subject: [PATCH] Rework Kafka Publisher to use DSL Spec for bean It is not recommended to use `IntegrationComponentSpec.getObject()` manually. * Change `KafkaPublisherConfiguration` to use `KafkaProducerMessageHandlerSpec` for bean definition * Fix `KafkaPublisherConfigurationTests` to add an `IntegrationAutoConfiguration` into the picture as well --- .../cloud/fn/consumer/kafka/KafkaPublisherConfiguration.java | 4 ++-- .../fn/consumer/kafka/KafkaPublisherConfigurationTests.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/consumer/kafka-publisher/src/main/java/org/springframework/cloud/fn/consumer/kafka/KafkaPublisherConfiguration.java b/consumer/kafka-publisher/src/main/java/org/springframework/cloud/fn/consumer/kafka/KafkaPublisherConfiguration.java index ad8821e4..b3be0ea2 100644 --- a/consumer/kafka-publisher/src/main/java/org/springframework/cloud/fn/consumer/kafka/KafkaPublisherConfiguration.java +++ b/consumer/kafka-publisher/src/main/java/org/springframework/cloud/fn/consumer/kafka/KafkaPublisherConfiguration.java @@ -59,7 +59,7 @@ public Consumer> kafkaPublisher(KafkaProducerMessageHandler kaf } @Bean - public KafkaProducerMessageHandler kafkaProducerMessageHandlerSpec(KafkaTemplate kafkaTemplate, + public KafkaProducerMessageHandlerSpec kafkaProducerMessageHandlerSpec(KafkaTemplate kafkaTemplate, KafkaPublisherProperties kafkaPublisherProperties, PublishSubscribeChannel kafkaPublisherSuccessChannel, PublishSubscribeChannel kafkaPublisherFailureChannel, @@ -91,7 +91,7 @@ public Consumer> kafkaPublisher(KafkaProducerMessageHandler kaf kafkaProducerSpecComponentCustomizer.customize(kafkaProducerMessageHandlerSpec); } - return kafkaProducerMessageHandlerSpec.getObject(); + return kafkaProducerMessageHandlerSpec; } /** diff --git a/consumer/kafka-publisher/src/test/java/org/springframework/cloud/fn/consumer/kafka/KafkaPublisherConfigurationTests.java b/consumer/kafka-publisher/src/test/java/org/springframework/cloud/fn/consumer/kafka/KafkaPublisherConfigurationTests.java index e7e3d8ac..23c387a5 100644 --- a/consumer/kafka-publisher/src/test/java/org/springframework/cloud/fn/consumer/kafka/KafkaPublisherConfigurationTests.java +++ b/consumer/kafka-publisher/src/test/java/org/springframework/cloud/fn/consumer/kafka/KafkaPublisherConfigurationTests.java @@ -30,6 +30,7 @@ import reactor.core.publisher.Sinks; import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.autoconfigure.integration.IntegrationAutoConfiguration; import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration; import org.springframework.boot.test.context.runner.ApplicationContextRunner; import org.springframework.cloud.fn.common.config.SpelExpressionConverterConfiguration; @@ -59,6 +60,7 @@ public class KafkaPublisherConfigurationTests { final ApplicationContextRunner contextRunner = new ApplicationContextRunner() .withConfiguration(AutoConfigurations.of( + IntegrationAutoConfiguration.class, KafkaAutoConfiguration.class, KafkaPublisherConfiguration.class, SpelExpressionConverterConfiguration.class));