GH-8586: Deprecate IntegrationComponentSpec.get() (#8594)
* GH-8586: Deprecate IntegrationComponentSpec.get() Fixes https://github.com/spring-projects/spring-integration/issues/8586 The `IntegrationComponentSpec` is not a plain wrapper around single component. Sometimes it comes with several components where all of them must be registered as beans. If `IntegrationComponentSpec.get()` is called from end-user code, we may lose other related components, for example filters in the `FileInboundChannelAdapterSpec`. * Deprecate `IntegrationComponentSpec.get()` with no-op for end-user, rather encourage to leave it as is and let the framework take care about its lifecycle and related components registration * Fix `IntegrationComponentSpec` logic to deal as a simple `FactoryBean` instead of extra overhead via `AbstractFactoryBean` * Use `IntegrationComponentSpec.getObject()` in the framework code where `get()` was called * Fix tests to expose `IntegrationComponentSpec` as beans instead of previously called `get()` * Some other clean up and typos fixes in the affected classes * Document the change * * Revert `ObjectStringMapBuilder` in the `KafkaInboundGatewaySpec.getComponentsToRegister()` * Fix language in docs Co-authored-by: Gary Russell <grussell@vmware.com> * * Remove trailing whitespace in the `ScriptMessageSourceSpec` --------- Co-authored-by: Gary Russell <grussell@vmware.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018-2021 the original author or authors.
|
||||
* Copyright 2018-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -102,6 +102,7 @@ public class KafkaInboundGatewaySpec<K, V, R, S extends KafkaInboundGatewaySpec<
|
||||
*/
|
||||
public S onPartitionsAssignedSeekCallback(
|
||||
BiConsumer<Map<TopicPartition, Long>, ConsumerSeekAware.ConsumerSeekCallback> onPartitionsAssignedCallback) {
|
||||
|
||||
this.target.setOnPartitionsAssignedSeekCallback(onPartitionsAssignedCallback);
|
||||
return _this();
|
||||
}
|
||||
@@ -128,7 +129,7 @@ public class KafkaInboundGatewaySpec<K, V, R, S extends KafkaInboundGatewaySpec<
|
||||
KafkaInboundGatewayListenerContainerSpec(KafkaMessageListenerContainerSpec<K, V> containerSpec,
|
||||
KafkaTemplateSpec<K, R> templateSpec) {
|
||||
|
||||
super(containerSpec.get(), templateSpec.getTemplate());
|
||||
super(containerSpec.getObject(), templateSpec.getTemplate());
|
||||
this.containerSpec = containerSpec;
|
||||
this.templateSpec = templateSpec;
|
||||
}
|
||||
@@ -164,8 +165,8 @@ public class KafkaInboundGatewaySpec<K, V, R, S extends KafkaInboundGatewaySpec<
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return new ObjectStringMapBuilder()
|
||||
.put(this.containerSpec.get(), this.containerSpec.getId())
|
||||
.put(this.templateSpec.get(), this.templateSpec.getId())
|
||||
.put(this.containerSpec.getObject(), this.containerSpec.getId())
|
||||
.put(this.templateSpec.getObject(), this.templateSpec.getId())
|
||||
.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2021 the original author or authors.
|
||||
* Copyright 2016-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -57,6 +57,7 @@ public class KafkaMessageDrivenChannelAdapterSpec<K, V, S extends KafkaMessageDr
|
||||
|
||||
KafkaMessageDrivenChannelAdapterSpec(AbstractMessageListenerContainer<K, V> messageListenerContainer,
|
||||
KafkaMessageDrivenChannelAdapter.ListenerMode listenerMode) {
|
||||
|
||||
super(new KafkaMessageDrivenChannelAdapter<>(messageListenerContainer, listenerMode));
|
||||
this.container = messageListenerContainer;
|
||||
}
|
||||
@@ -174,6 +175,7 @@ public class KafkaMessageDrivenChannelAdapterSpec<K, V, S extends KafkaMessageDr
|
||||
*/
|
||||
public S onPartitionsAssignedSeekCallback(
|
||||
BiConsumer<Map<TopicPartition, Long>, ConsumerSeekAware.ConsumerSeekCallback> onPartitionsAssignedCallback) {
|
||||
|
||||
this.target.setOnPartitionsAssignedSeekCallback(onPartitionsAssignedCallback);
|
||||
return _this();
|
||||
}
|
||||
@@ -196,7 +198,7 @@ public class KafkaMessageDrivenChannelAdapterSpec<K, V, S extends KafkaMessageDr
|
||||
|
||||
KafkaMessageDrivenChannelAdapterListenerContainerSpec(KafkaMessageListenerContainerSpec<K, V> spec,
|
||||
KafkaMessageDrivenChannelAdapter.ListenerMode listenerMode) {
|
||||
super(spec.get(), listenerMode);
|
||||
super(spec.getObject(), listenerMode);
|
||||
this.spec = spec;
|
||||
}
|
||||
|
||||
@@ -208,6 +210,7 @@ public class KafkaMessageDrivenChannelAdapterSpec<K, V, S extends KafkaMessageDr
|
||||
*/
|
||||
public KafkaMessageDrivenChannelAdapterListenerContainerSpec<K, V> configureListenerContainer(
|
||||
Consumer<KafkaMessageListenerContainerSpec<K, V>> configurer) {
|
||||
|
||||
Assert.notNull(configurer, "The 'configurer' cannot be null");
|
||||
configurer.accept(this.spec);
|
||||
return _this();
|
||||
@@ -215,7 +218,7 @@ public class KafkaMessageDrivenChannelAdapterSpec<K, V, S extends KafkaMessageDr
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return Collections.singletonMap(this.spec.get(), this.spec.getId());
|
||||
return Collections.singletonMap(this.spec.getObject(), this.spec.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018-2022 the original author or authors.
|
||||
* Copyright 2018-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -110,7 +110,7 @@ public class KafkaOutboundGatewaySpec<K, V, R, S extends KafkaOutboundGatewaySpe
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return Collections.singletonMap(this.kafkaTemplateSpec.get(), this.kafkaTemplateSpec.getId());
|
||||
return Collections.singletonMap(this.kafkaTemplateSpec.getTemplate(), this.kafkaTemplateSpec.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2021 the original author or authors.
|
||||
* Copyright 2016-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -429,10 +429,9 @@ public class KafkaProducerMessageHandlerSpec<K, V, S extends KafkaProducerMessag
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return Collections.singletonMap(this.kafkaTemplateSpec.get(), this.kafkaTemplateSpec.getId());
|
||||
return Collections.singletonMap(this.kafkaTemplateSpec.getTemplate(), this.kafkaTemplateSpec.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015-2022 the original author or authors.
|
||||
* Copyright 2015-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,12 +38,12 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.MessageRejectedException;
|
||||
import org.springframework.integration.channel.BroadcastCapableChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.EnableIntegration;
|
||||
import org.springframework.integration.dsl.IntegrationFlow;
|
||||
import org.springframework.integration.dsl.Pollers;
|
||||
import org.springframework.integration.kafka.channel.PollableKafkaChannel;
|
||||
import org.springframework.integration.kafka.channel.PublishSubscribeKafkaChannel;
|
||||
import org.springframework.integration.kafka.inbound.KafkaErrorSendingMessageRecoverer;
|
||||
import org.springframework.integration.kafka.inbound.KafkaInboundGateway;
|
||||
import org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter;
|
||||
@@ -427,10 +427,11 @@ public class KafkaDslTests {
|
||||
@Bean
|
||||
public IntegrationFlow channels(KafkaTemplate<Integer, String> template,
|
||||
ConcurrentKafkaListenerContainerFactory<Integer, String> containerFactory,
|
||||
KafkaMessageSource<?, ?> channelSource) {
|
||||
KafkaMessageSource<?, ?> channelSource,
|
||||
PublishSubscribeKafkaChannel publishSubscribeKafkaChannel) {
|
||||
|
||||
return IntegrationFlow.from(topic6Channel(template, containerFactory))
|
||||
.publishSubscribeChannel(pubSub(template, containerFactory), channel -> channel
|
||||
.publishSubscribeChannel(publishSubscribeKafkaChannel, channel -> channel
|
||||
.subscribe(f -> f.channel(
|
||||
Kafka.pollableChannel(template, channelSource).id("topic8Channel")))
|
||||
.subscribe(f -> f.channel(
|
||||
@@ -439,11 +440,10 @@ public class KafkaDslTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BroadcastCapableChannel pubSub(KafkaTemplate<Integer, String> template,
|
||||
public KafkaPublishSubscribeChannelSpec pubSub(KafkaTemplate<Integer, String> template,
|
||||
ConcurrentKafkaListenerContainerFactory<Integer, String> containerFactory) {
|
||||
|
||||
return Kafka.publishSubscribeChannel(template, containerFactory, TEST_TOPIC7)
|
||||
.get();
|
||||
return Kafka.publishSubscribeChannel(template, containerFactory, TEST_TOPIC7);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -539,7 +539,7 @@ class MessageDrivenAdapterTests {
|
||||
.messageDrivenChannelAdapter(container, ListenerMode.record)
|
||||
.recordMessageConverter(new StringJsonMessageConverter())
|
||||
.payloadType(Foo.class)
|
||||
.get();
|
||||
.getObject();
|
||||
QueueChannel out = new QueueChannel();
|
||||
adapter.setOutputChannel(out);
|
||||
adapter.afterPropertiesSet();
|
||||
|
||||
Reference in New Issue
Block a user