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:
Artem Bilan
2023-04-13 09:16:42 -04:00
committed by GitHub
parent bbaffb22bf
commit b99729544d
46 changed files with 401 additions and 369 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 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.
@@ -43,13 +43,13 @@ public abstract class AmqpInboundChannelAdapterSpec
protected final MessageListenerContainerSpec<?, C> listenerContainerSpec; // NOSONAR final
protected AmqpInboundChannelAdapterSpec(MessageListenerContainerSpec<?, C> listenerContainerSpec) {
super(new AmqpInboundChannelAdapter(listenerContainerSpec.get()));
super(new AmqpInboundChannelAdapter(listenerContainerSpec.getObject()));
this.listenerContainerSpec = listenerContainerSpec;
}
@Override
public Map<Object, String> getComponentsToRegister() {
return Collections.singletonMap(this.listenerContainerSpec.get(), this.listenerContainerSpec.getId());
return Collections.singletonMap(this.listenerContainerSpec.getObject(), this.listenerContainerSpec.getId());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 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.
@@ -43,7 +43,7 @@ public abstract class AmqpInboundGatewaySpec
protected final AbstractMessageListenerContainerSpec<?, C> listenerContainerSpec; // NOSONAR final
protected AmqpInboundGatewaySpec(AbstractMessageListenerContainerSpec<?, C> listenerContainerSpec) {
super(new AmqpInboundGateway(listenerContainerSpec.get()));
super(new AmqpInboundGateway(listenerContainerSpec.getObject()));
this.listenerContainerSpec = listenerContainerSpec;
}
@@ -53,16 +53,16 @@ public abstract class AmqpInboundGatewaySpec
* @param listenerContainerSpec the {@link AbstractMessageListenerContainerSpec} to use.
* @param amqpTemplate the {@link AmqpTemplate} to use.
*/
AmqpInboundGatewaySpec(
AbstractMessageListenerContainerSpec<?, C> listenerContainerSpec,
AmqpInboundGatewaySpec(AbstractMessageListenerContainerSpec<?, C> listenerContainerSpec,
AmqpTemplate amqpTemplate) {
super(new AmqpInboundGateway(listenerContainerSpec.get(), amqpTemplate));
super(new AmqpInboundGateway(listenerContainerSpec.getObject(), amqpTemplate));
this.listenerContainerSpec = listenerContainerSpec;
}
@Override
public Map<Object, String> getComponentsToRegister() {
return Collections.singletonMap(this.listenerContainerSpec.get(), this.listenerContainerSpec.getId());
return Collections.singletonMap(this.listenerContainerSpec.getObject(), this.listenerContainerSpec.getId());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022 the original author or authors.
* Copyright 2022-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.
@@ -122,7 +122,7 @@ public class RabbitStreamMessageHandlerSpec
* Set to true to wait for a confirmation.
* @param sync true to wait.
* @return this spec.
* @see #setConfirmTimeout(long)
* @see #confirmTimeout(long)
*/
public RabbitStreamMessageHandlerSpec sync(boolean sync) {
this.target.setSync(sync);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 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.
@@ -50,6 +50,7 @@ import org.springframework.context.Lifecycle;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.amqp.channel.AbstractAmqpChannel;
import org.springframework.integration.amqp.channel.PollableAmqpChannel;
import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter.BatchMode;
import org.springframework.integration.amqp.inbound.AmqpInboundGateway;
import org.springframework.integration.amqp.support.AmqpHeaderMapper;
@@ -472,15 +473,16 @@ public class AmqpTests {
}
@Bean
public AbstractAmqpChannel unitChannel(ConnectionFactory rabbitConnectionFactory) {
public AmqpPollableMessageChannelSpec<?, PollableAmqpChannel> unitChannel(
ConnectionFactory rabbitConnectionFactory) {
return Amqp.pollableChannel(rabbitConnectionFactory)
.queueName("si.dsl.test")
.channelTransacted(true)
.extractPayload(true)
.inboundHeaderMapper(mapperIn())
.outboundHeaderMapper(mapperOut())
.defaultDeliveryMode(MessageDeliveryMode.NON_PERSISTENT)
.get();
.defaultDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
}
@Bean

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 the original author or authors.
* Copyright 2021-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.
@@ -36,6 +36,8 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Gary Russell
* @author Chris Bono
* @author Artem Bilan
*
* @since 6.0
*/
public class RabbitStreamMessageHandlerTests implements RabbitTestContainer {
@@ -56,7 +58,7 @@ public class RabbitStreamMessageHandlerTests implements RabbitTestContainer {
RabbitStreamMessageHandler handler = RabbitStream.outboundStreamAdapter(streamTemplate)
.sync(true)
.get();
.getObject();
handler.handleMessage(MessageBuilder.withPayload("foo")
.setHeader("bar", "baz")