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 2014-2021 the original author or authors.
|
||||
* Copyright 2014-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.
|
||||
@@ -208,7 +208,7 @@ public final class Jms {
|
||||
public static JmsMessageDrivenChannelAdapterSpec<?> messageDrivenChannelAdapter(
|
||||
JmsListenerContainerSpec<?, ? extends AbstractMessageListenerContainer> jmsListenerContainerSpec) {
|
||||
|
||||
return new JmsMessageDrivenChannelAdapterSpec<>(jmsListenerContainerSpec.get());
|
||||
return new JmsMessageDrivenChannelAdapterSpec<>(jmsListenerContainerSpec.getObject());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +216,9 @@ public final class Jms {
|
||||
* @param listenerContainer the {@link AbstractMessageListenerContainer} to build on
|
||||
* @return the {@link JmsMessageDrivenChannelAdapterSpec} instance
|
||||
*/
|
||||
public static JmsMessageDrivenChannelAdapterSpec<?> messageDrivenChannelAdapter(AbstractMessageListenerContainer listenerContainer) {
|
||||
public static JmsMessageDrivenChannelAdapterSpec<?> messageDrivenChannelAdapter(
|
||||
AbstractMessageListenerContainer listenerContainer) {
|
||||
|
||||
return new JmsMessageDrivenChannelAdapterSpec<>(listenerContainer);
|
||||
}
|
||||
|
||||
@@ -227,14 +229,10 @@ public final class Jms {
|
||||
*/
|
||||
public static JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<JmsDefaultListenerContainerSpec, DefaultMessageListenerContainer>
|
||||
messageDrivenChannelAdapter(ConnectionFactory connectionFactory) {
|
||||
try {
|
||||
return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<>(
|
||||
new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory));
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<>(
|
||||
new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,15 +247,11 @@ public final class Jms {
|
||||
public static <C extends AbstractMessageListenerContainer>
|
||||
JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec<?, C>
|
||||
messageDrivenChannelAdapter(ConnectionFactory connectionFactory, Class<C> containerClass) {
|
||||
try {
|
||||
JmsListenerContainerSpec<?, C> spec =
|
||||
new JmsListenerContainerSpec<>(containerClass)
|
||||
.connectionFactory(connectionFactory);
|
||||
return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec(spec);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
JmsListenerContainerSpec<?, C> spec =
|
||||
new JmsListenerContainerSpec<>(containerClass)
|
||||
.connectionFactory(connectionFactory);
|
||||
return new JmsMessageDrivenChannelAdapterSpec.JmsMessageDrivenChannelAdapterListenerContainerSpec(spec);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -268,14 +262,10 @@ public final class Jms {
|
||||
*/
|
||||
public static JmsDefaultListenerContainerSpec container(ConnectionFactory connectionFactory,
|
||||
Destination destination) {
|
||||
try {
|
||||
return new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory)
|
||||
.destination(destination);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
return new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory)
|
||||
.destination(destination);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,14 +276,10 @@ public final class Jms {
|
||||
*/
|
||||
public static JmsDefaultListenerContainerSpec container(ConnectionFactory connectionFactory,
|
||||
String destinationName) {
|
||||
try {
|
||||
return new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory)
|
||||
.destination(destinationName);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
return new JmsDefaultListenerContainerSpec()
|
||||
.connectionFactory(connectionFactory)
|
||||
.destination(destinationName);
|
||||
}
|
||||
|
||||
private Jms() {
|
||||
|
||||
@@ -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.
|
||||
@@ -49,7 +49,8 @@ public class JmsInboundChannelAdapterSpec<S extends JmsInboundChannelAdapterSpec
|
||||
}
|
||||
|
||||
private JmsInboundChannelAdapterSpec(ConnectionFactory connectionFactory) {
|
||||
this.target = new JmsDestinationPollingSource(this.jmsTemplateSpec.connectionFactory(connectionFactory).get());
|
||||
this.target =
|
||||
new JmsDestinationPollingSource(this.jmsTemplateSpec.connectionFactory(connectionFactory).getObject());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +119,7 @@ public class JmsInboundChannelAdapterSpec<S extends JmsInboundChannelAdapterSpec
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return Collections.singletonMap(this.jmsTemplateSpec.get(), this.jmsTemplateSpec.getId());
|
||||
return Collections.singletonMap(this.jmsTemplateSpec.getObject(), this.jmsTemplateSpec.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -246,9 +246,9 @@ public class JmsInboundGatewaySpec<S extends JmsInboundGatewaySpec<S>>
|
||||
private final S spec;
|
||||
|
||||
protected JmsInboundGatewayListenerContainerSpec(S spec) {
|
||||
super(spec.get());
|
||||
super(spec.getObject());
|
||||
this.spec = spec;
|
||||
this.spec.get().setAutoStartup(false);
|
||||
this.spec.getObject().setAutoStartup(false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
@@ -80,9 +80,9 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
|
||||
}
|
||||
|
||||
/**
|
||||
* Set to false to prevent listener container shutdown when the endpoint is stopped.
|
||||
* Set to 'false' to prevent listener container shutdown when the endpoint is stopped.
|
||||
* Then, if so configured, any cached consumer(s) in the container will remain.
|
||||
* Otherwise the shared connection and will be closed and the listener invokers shut
|
||||
* Otherwise, the shared connection and will be closed and the listener invokers shut
|
||||
* down; this behavior is new starting with version 5.1. Default: true.
|
||||
* @param shutdown false to not shutdown.
|
||||
* @return the spec.
|
||||
@@ -106,9 +106,9 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
|
||||
private final S spec;
|
||||
|
||||
protected JmsMessageDrivenChannelAdapterListenerContainerSpec(S spec) {
|
||||
super(spec.get());
|
||||
super(spec.getObject());
|
||||
this.spec = spec;
|
||||
this.spec.get().setAutoStartup(false);
|
||||
this.spec.getObject().setAutoStartup(false);
|
||||
|
||||
}
|
||||
|
||||
@@ -141,6 +141,7 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
|
||||
*/
|
||||
public JmsMessageDrivenChannelAdapterListenerContainerSpec<S, C> configureListenerContainer(
|
||||
Consumer<S> configurer) {
|
||||
|
||||
Assert.notNull(configurer, "'configurer' must not be null");
|
||||
configurer.accept(this.spec);
|
||||
return _this();
|
||||
@@ -148,7 +149,7 @@ public class JmsMessageDrivenChannelAdapterSpec<S extends JmsMessageDrivenChanne
|
||||
|
||||
@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 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.
|
||||
@@ -51,7 +51,8 @@ public class JmsOutboundChannelAdapterSpec<S extends JmsOutboundChannelAdapterSp
|
||||
}
|
||||
|
||||
private JmsOutboundChannelAdapterSpec(ConnectionFactory connectionFactory) {
|
||||
this.target = new JmsSendingMessageHandler(this.jmsTemplateSpec.connectionFactory(connectionFactory).get());
|
||||
this.target =
|
||||
new JmsSendingMessageHandler(this.jmsTemplateSpec.connectionFactory(connectionFactory).getObject());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +102,7 @@ public class JmsOutboundChannelAdapterSpec<S extends JmsOutboundChannelAdapterSp
|
||||
* which a message will be sent.
|
||||
* @param destination the destination name.
|
||||
* @return the current {@link JmsOutboundChannelAdapterSpec}.
|
||||
* @see JmsSendingMessageHandler#setDestinationExpression(Expression)
|
||||
* @see JmsSendingMessageHandler#setDestinationExpression
|
||||
*/
|
||||
public S destinationExpression(String destination) {
|
||||
this.target.setDestinationExpression(PARSER.parseExpression(destination));
|
||||
@@ -119,7 +120,7 @@ public class JmsOutboundChannelAdapterSpec<S extends JmsOutboundChannelAdapterSp
|
||||
* @param destinationFunction the destination function.
|
||||
* @param <P> the expected payload type.
|
||||
* @return the current {@link JmsOutboundChannelAdapterSpec}.
|
||||
* @see JmsSendingMessageHandler#setDestinationExpression(Expression)
|
||||
* @see JmsSendingMessageHandler#setDestinationExpression
|
||||
* @see FunctionExpression
|
||||
*/
|
||||
public <P> S destination(Function<Message<P>, ?> destinationFunction) {
|
||||
@@ -194,7 +195,7 @@ public class JmsOutboundChannelAdapterSpec<S extends JmsOutboundChannelAdapterSp
|
||||
|
||||
@Override
|
||||
public Map<Object, String> getComponentsToRegister() {
|
||||
return Collections.singletonMap(this.jmsTemplateSpec.get(), this.jmsTemplateSpec.getId());
|
||||
return Collections.singletonMap(this.jmsTemplateSpec.getObject(), this.jmsTemplateSpec.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.
|
||||
@@ -296,7 +296,7 @@ public class JmsOutboundGatewaySpec extends MessageHandlerSpec<JmsOutboundGatewa
|
||||
Assert.notNull(configurer, "'configurer' must not be null");
|
||||
ReplyContainerSpec spec = new ReplyContainerSpec();
|
||||
configurer.accept(spec);
|
||||
this.target.setReplyContainerProperties(spec.get());
|
||||
this.target.setReplyContainerProperties(spec.getObject());
|
||||
return _this();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.integration.annotation.InboundChannelAdapter;
|
||||
import org.springframework.integration.annotation.IntegrationComponentScan;
|
||||
import org.springframework.integration.annotation.MessagingGateway;
|
||||
import org.springframework.integration.annotation.Poller;
|
||||
import org.springframework.integration.channel.BroadcastCapableChannel;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.FixedSubscriberChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
@@ -46,11 +45,14 @@ import org.springframework.integration.core.MessageSource;
|
||||
import org.springframework.integration.dsl.IntegrationFlow;
|
||||
import org.springframework.integration.dsl.IntegrationFlowDefinition;
|
||||
import org.springframework.integration.dsl.MessageChannels;
|
||||
import org.springframework.integration.dsl.PollerSpec;
|
||||
import org.springframework.integration.dsl.Pollers;
|
||||
import org.springframework.integration.dsl.QueueChannelSpec;
|
||||
import org.springframework.integration.endpoint.MethodInvokingMessageSource;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.jms.ActiveMQMultiContextTests;
|
||||
import org.springframework.integration.jms.JmsDestinationPollingSource;
|
||||
import org.springframework.integration.jms.SubscribableJmsChannel;
|
||||
import org.springframework.integration.scheduling.PollerMetadata;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
@@ -302,8 +304,8 @@ public class JmsTests extends ActiveMQMultiContextTests {
|
||||
}
|
||||
|
||||
@Bean(name = PollerMetadata.DEFAULT_POLLER)
|
||||
public PollerMetadata poller() {
|
||||
return Pollers.fixedDelay(1000).get();
|
||||
public PollerSpec poller() {
|
||||
return Pollers.fixedDelay(1000);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -338,30 +340,29 @@ public class JmsTests extends ActiveMQMultiContextTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageChannel jmsOutboundInboundReplyChannel() {
|
||||
return MessageChannels.queue().get();
|
||||
public QueueChannelSpec jmsOutboundInboundReplyChannel() {
|
||||
return MessageChannels.queue();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IntegrationFlow jmsInboundFlow() {
|
||||
public IntegrationFlow jmsInboundFlow(QueueChannel jmsOutboundInboundReplyChannel) {
|
||||
return IntegrationFlow
|
||||
.from(Jms.inboundAdapter(amqFactory).destination("jmsInbound"))
|
||||
.<String, String>transform(String::toUpperCase)
|
||||
.channel(this.jmsOutboundInboundReplyChannel())
|
||||
.channel(jmsOutboundInboundReplyChannel)
|
||||
.get();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BroadcastCapableChannel jmsPublishSubscribeChannel() {
|
||||
public JmsPublishSubscribeMessageChannelSpec jmsPublishSubscribeChannel() {
|
||||
return Jms.publishSubscribeChannel(amqFactory)
|
||||
.destination("pubsub")
|
||||
.get();
|
||||
.destination("pubsub");
|
||||
}
|
||||
|
||||
@Bean
|
||||
public IntegrationFlow pubSubFlow() {
|
||||
public IntegrationFlow pubSubFlow(SubscribableJmsChannel jmsPublishSubscribeChannel) {
|
||||
return f -> f
|
||||
.publishSubscribeChannel(jmsPublishSubscribeChannel(),
|
||||
.publishSubscribeChannel(jmsPublishSubscribeChannel,
|
||||
pubsub -> pubsub
|
||||
.subscribe(subFlow -> subFlow
|
||||
.channel(c -> c.queue("jmsPubSubBridgeChannel")))
|
||||
@@ -408,8 +409,7 @@ public class JmsTests extends ActiveMQMultiContextTests {
|
||||
.from(Jms.messageDrivenChannelAdapter(
|
||||
Jms.container(amqFactory, "containerSpecDestination")
|
||||
.pubSubDomain(false)
|
||||
.taskExecutor(Executors.newCachedThreadPool())
|
||||
.get()))
|
||||
.taskExecutor(Executors.newCachedThreadPool())))
|
||||
.transform(String::trim)
|
||||
.channel(jmsOutboundInboundReplyChannel())
|
||||
.get();
|
||||
|
||||
@@ -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.
|
||||
@@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Qualifier
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor
|
||||
import org.springframework.integration.channel.QueueChannel
|
||||
import org.springframework.integration.config.EnableIntegration
|
||||
import org.springframework.integration.dsl.MessageChannels
|
||||
import org.springframework.integration.dsl.integrationFlow
|
||||
@@ -112,10 +113,10 @@ class JmsDslKotlinTests : ActiveMQMultiContextTests() {
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun jmsOutboundInboundReplyChannel() = MessageChannels.queue().get()
|
||||
fun jmsOutboundInboundReplyChannel() = MessageChannels.queue()
|
||||
|
||||
@Bean
|
||||
fun jmsMessageDrivenFlowWithContainer() =
|
||||
fun jmsMessageDrivenFlowWithContainer(jmsOutboundInboundReplyChannel: QueueChannel) =
|
||||
integrationFlow(
|
||||
Jms.messageDrivenChannelAdapter(
|
||||
Jms.container(amqFactory, "containerSpecDestination")
|
||||
@@ -125,7 +126,7 @@ class JmsDslKotlinTests : ActiveMQMultiContextTests() {
|
||||
.headerMapper(jmsHeaderMapper())
|
||||
) {
|
||||
transform { it: String -> it.trim { it <= ' ' } }
|
||||
channel(jmsOutboundInboundReplyChannel())
|
||||
channel(jmsOutboundInboundReplyChannel)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user