Skip to content

Commit

Permalink
GH-8586: Deprecate IntegrationComponentSpec.get() (#8594)
Browse files Browse the repository at this point in the history
* 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 <grussell@vmware.com>

* * Remove trailing whitespace in the `ScriptMessageSourceSpec`

---------

Co-authored-by: Gary Russell <grussell@vmware.com>
  • Loading branch information
artembilan and garyrussell authored Apr 13, 2023
1 parent bbaffb2 commit b997295
Show file tree
Hide file tree
Showing 46 changed files with 401 additions and 369 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
}

Expand All @@ -53,16 +53,16 @@ protected AmqpInboundGatewaySpec(AbstractMessageListenerContainerSpec<?, C> list
* @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());
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -122,7 +122,7 @@ public RabbitStreamMessageHandlerSpec sendFailureChannel(String channel) {
* 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -50,6 +50,7 @@
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;
Expand Down Expand Up @@ -472,15 +473,16 @@ public IntegrationFlow amqpAsyncOutboundFlow(AsyncRabbitTemplate asyncRabbitTemp
}

@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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -36,6 +36,8 @@
/**
* @author Gary Russell
* @author Chris Bono
* @author Artem Bilan
*
* @since 6.0
*/
public class RabbitStreamMessageHandlerTests implements RabbitTestContainer {
Expand All @@ -56,7 +58,7 @@ void convertAndSend() throws InterruptedException {

RabbitStreamMessageHandler handler = RabbitStream.outboundStreamAdapter(streamTemplate)
.sync(true)
.get();
.getObject();

handler.handleMessage(MessageBuilder.withPayload("foo")
.setHeader("bar", "baz")
Expand Down
Loading

0 comments on commit b997295

Please sign in to comment.