Skip to content

Commit

Permalink
Rework Kafka Publisher to use DSL Spec for bean
Browse files Browse the repository at this point in the history
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
  • Loading branch information
artembilan committed Nov 27, 2023
1 parent fc71db4 commit 52e506e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Consumer<Message<?>> kafkaPublisher(KafkaProducerMessageHandler<?, ?> kaf
}

@Bean
public KafkaProducerMessageHandler<?, ?> kafkaProducerMessageHandlerSpec(KafkaTemplate<?, ?> kafkaTemplate,
public KafkaProducerMessageHandlerSpec<?, ?, ?> kafkaProducerMessageHandlerSpec(KafkaTemplate<?, ?> kafkaTemplate,
KafkaPublisherProperties kafkaPublisherProperties,
PublishSubscribeChannel kafkaPublisherSuccessChannel,
PublishSubscribeChannel kafkaPublisherFailureChannel,
Expand Down Expand Up @@ -91,7 +91,7 @@ public Consumer<Message<?>> kafkaPublisher(KafkaProducerMessageHandler<?, ?> kaf
kafkaProducerSpecComponentCustomizer.customize(kafkaProducerMessageHandlerSpec);
}

return kafkaProducerMessageHandlerSpec.getObject();
return kafkaProducerMessageHandlerSpec;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,6 +60,7 @@ public class KafkaPublisherConfigurationTests {

final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(
IntegrationAutoConfiguration.class,
KafkaAutoConfiguration.class,
KafkaPublisherConfiguration.class,
SpelExpressionConverterConfiguration.class));
Expand Down

0 comments on commit 52e506e

Please sign in to comment.