Skip to content

Commit b997295

Browse files
GH-8586: Deprecate IntegrationComponentSpec.get() (#8594)
* GH-8586: Deprecate IntegrationComponentSpec.get() Fixes #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 <[email protected]> * * Remove trailing whitespace in the `ScriptMessageSourceSpec` --------- Co-authored-by: Gary Russell <[email protected]>
1 parent bbaffb2 commit b997295

File tree

46 files changed

+401
-369
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+401
-369
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpInboundChannelAdapterSpec.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,13 +43,13 @@ public abstract class AmqpInboundChannelAdapterSpec
4343
protected final MessageListenerContainerSpec<?, C> listenerContainerSpec; // NOSONAR final
4444

4545
protected AmqpInboundChannelAdapterSpec(MessageListenerContainerSpec<?, C> listenerContainerSpec) {
46-
super(new AmqpInboundChannelAdapter(listenerContainerSpec.get()));
46+
super(new AmqpInboundChannelAdapter(listenerContainerSpec.getObject()));
4747
this.listenerContainerSpec = listenerContainerSpec;
4848
}
4949

5050
@Override
5151
public Map<Object, String> getComponentsToRegister() {
52-
return Collections.singletonMap(this.listenerContainerSpec.get(), this.listenerContainerSpec.getId());
52+
return Collections.singletonMap(this.listenerContainerSpec.getObject(), this.listenerContainerSpec.getId());
5353
}
5454

5555
}

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpInboundGatewaySpec.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -43,7 +43,7 @@ public abstract class AmqpInboundGatewaySpec
4343
protected final AbstractMessageListenerContainerSpec<?, C> listenerContainerSpec; // NOSONAR final
4444

4545
protected AmqpInboundGatewaySpec(AbstractMessageListenerContainerSpec<?, C> listenerContainerSpec) {
46-
super(new AmqpInboundGateway(listenerContainerSpec.get()));
46+
super(new AmqpInboundGateway(listenerContainerSpec.getObject()));
4747
this.listenerContainerSpec = listenerContainerSpec;
4848
}
4949

@@ -53,16 +53,16 @@ protected AmqpInboundGatewaySpec(AbstractMessageListenerContainerSpec<?, C> list
5353
* @param listenerContainerSpec the {@link AbstractMessageListenerContainerSpec} to use.
5454
* @param amqpTemplate the {@link AmqpTemplate} to use.
5555
*/
56-
AmqpInboundGatewaySpec(
57-
AbstractMessageListenerContainerSpec<?, C> listenerContainerSpec,
56+
AmqpInboundGatewaySpec(AbstractMessageListenerContainerSpec<?, C> listenerContainerSpec,
5857
AmqpTemplate amqpTemplate) {
59-
super(new AmqpInboundGateway(listenerContainerSpec.get(), amqpTemplate));
58+
59+
super(new AmqpInboundGateway(listenerContainerSpec.getObject(), amqpTemplate));
6060
this.listenerContainerSpec = listenerContainerSpec;
6161
}
6262

6363
@Override
6464
public Map<Object, String> getComponentsToRegister() {
65-
return Collections.singletonMap(this.listenerContainerSpec.get(), this.listenerContainerSpec.getId());
65+
return Collections.singletonMap(this.listenerContainerSpec.getObject(), this.listenerContainerSpec.getId());
6666
}
6767

6868
}

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/RabbitStreamMessageHandlerSpec.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 the original author or authors.
2+
* Copyright 2022-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -122,7 +122,7 @@ public RabbitStreamMessageHandlerSpec sendFailureChannel(String channel) {
122122
* Set to true to wait for a confirmation.
123123
* @param sync true to wait.
124124
* @return this spec.
125-
* @see #setConfirmTimeout(long)
125+
* @see #confirmTimeout(long)
126126
*/
127127
public RabbitStreamMessageHandlerSpec sync(boolean sync) {
128128
this.target.setSync(sync);

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/dsl/AmqpTests.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,6 +50,7 @@
5050
import org.springframework.context.annotation.Bean;
5151
import org.springframework.context.annotation.Configuration;
5252
import org.springframework.integration.amqp.channel.AbstractAmqpChannel;
53+
import org.springframework.integration.amqp.channel.PollableAmqpChannel;
5354
import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter.BatchMode;
5455
import org.springframework.integration.amqp.inbound.AmqpInboundGateway;
5556
import org.springframework.integration.amqp.support.AmqpHeaderMapper;
@@ -472,15 +473,16 @@ public IntegrationFlow amqpAsyncOutboundFlow(AsyncRabbitTemplate asyncRabbitTemp
472473
}
473474

474475
@Bean
475-
public AbstractAmqpChannel unitChannel(ConnectionFactory rabbitConnectionFactory) {
476+
public AmqpPollableMessageChannelSpec<?, PollableAmqpChannel> unitChannel(
477+
ConnectionFactory rabbitConnectionFactory) {
478+
476479
return Amqp.pollableChannel(rabbitConnectionFactory)
477480
.queueName("si.dsl.test")
478481
.channelTransacted(true)
479482
.extractPayload(true)
480483
.inboundHeaderMapper(mapperIn())
481484
.outboundHeaderMapper(mapperOut())
482-
.defaultDeliveryMode(MessageDeliveryMode.NON_PERSISTENT)
483-
.get();
485+
.defaultDeliveryMode(MessageDeliveryMode.NON_PERSISTENT);
484486
}
485487

486488
@Bean

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/RabbitStreamMessageHandlerTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021-2022 the original author or authors.
2+
* Copyright 2021-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,6 +36,8 @@
3636
/**
3737
* @author Gary Russell
3838
* @author Chris Bono
39+
* @author Artem Bilan
40+
*
3941
* @since 6.0
4042
*/
4143
public class RabbitStreamMessageHandlerTests implements RabbitTestContainer {
@@ -56,7 +58,7 @@ void convertAndSend() throws InterruptedException {
5658

5759
RabbitStreamMessageHandler handler = RabbitStream.outboundStreamAdapter(streamTemplate)
5860
.sync(true)
59-
.get();
61+
.getObject();
6062

6163
handler.handleMessage(MessageBuilder.withPayload("foo")
6264
.setHeader("bar", "baz")

0 commit comments

Comments
 (0)