Skip to content

Commit a577652

Browse files
artembilangaryrussell
authored andcommitted
Fix SourcePollingChAdFB autoStartup propagation
The `spring.integration.properties` can come with the `noAutoStartup` property where we can specify a source polling channel adapter endpoint to not start automatically. Turns out the `SourcePollingChannelAdapterFactoryBean` propagates its `autoStartup` property unconditionally which will skip the `noAutoStartup` value because an `AbstractEndpoint.setAutoStartup()` sets an `autoStartupSetExplicitly` state * Fix `SourcePollingChannelAdapterFactoryBean` to rely on a `Boolean` object state and don't call target endpoint `setAutoStartup()` if it was not set * Adjust `spring.integration.properties` in tests to use `noAutoStartup` for some `SourcePollingChannelAdapterFactoryBean` * Verify that property was applied in the `IntegrationFlowTests.testWithSupplierMessageSourceImpliedPoller()` **Cherry-pick to `5.4.x` & `5.3.x`**
1 parent db4f120 commit a577652

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

spring-integration-core/src/main/java/org/springframework/integration/config/SourcePollingChannelAdapterFactoryBean.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -55,7 +55,7 @@ public class SourcePollingChannelAdapterFactoryBean implements FactoryBean<Sourc
5555

5656
private PollerMetadata pollerMetadata;
5757

58-
private boolean autoStartup = true;
58+
private Boolean autoStartup;
5959

6060
private int phase = Integer.MAX_VALUE / 2;
6161

@@ -96,7 +96,7 @@ public void setPollerMetadata(PollerMetadata pollerMetadata) {
9696
this.pollerMetadata = pollerMetadata;
9797
}
9898

99-
public void setAutoStartup(boolean autoStartup) {
99+
public void setAutoStartup(Boolean autoStartup) {
100100
this.autoStartup = autoStartup;
101101
}
102102

@@ -178,7 +178,7 @@ private void initializeAdapter() {
178178

179179
if (this.pollerMetadata == null) {
180180
this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory);
181-
Assert.notNull(this.pollerMetadata, "No poller has been defined for channel-adapter '"
181+
Assert.notNull(this.pollerMetadata, () -> "No poller has been defined for channel-adapter '"
182182
+ this.beanName + "', and no default poller is available within the context.");
183183
}
184184
if (this.pollerMetadata.getMaxMessagesPerPoll() == Integer.MIN_VALUE) {
@@ -195,7 +195,9 @@ private void initializeAdapter() {
195195
spca.setTrigger(this.pollerMetadata.getTrigger());
196196
spca.setErrorHandler(this.pollerMetadata.getErrorHandler());
197197
spca.setBeanClassLoader(this.beanClassLoader);
198-
spca.setAutoStartup(this.autoStartup);
198+
if (this.autoStartup != null) {
199+
spca.setAutoStartup(this.autoStartup);
200+
}
199201
spca.setPhase(this.phase);
200202
spca.setRole(this.role);
201203
spca.setBeanName(this.beanName);

spring-integration-core/src/test/java/org/springframework/integration/dsl/flows/IntegrationFlowTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.springframework.integration.dsl.MessageChannels;
6565
import org.springframework.integration.dsl.Pollers;
6666
import org.springframework.integration.dsl.Transformers;
67+
import org.springframework.integration.endpoint.AbstractEndpoint;
6768
import org.springframework.integration.endpoint.EventDrivenConsumer;
6869
import org.springframework.integration.gateway.GatewayProxyFactoryBean;
6970
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
@@ -180,8 +181,14 @@ public class IntegrationFlowTests {
180181
@Qualifier("lambdasInput")
181182
private MessageChannel lambdasInput;
182183

184+
@Autowired
185+
AbstractEndpoint stringSupplierEndpoint;
186+
183187
@Test
184188
public void testWithSupplierMessageSourceImpliedPoller() {
189+
assertThat(this.stringSupplierEndpoint.isAutoStartup()).isFalse();
190+
assertThat(this.stringSupplierEndpoint.isRunning()).isFalse();
191+
this.stringSupplierEndpoint.start();
185192
assertThat(this.suppliedChannel.receive(10000).getPayload()).isEqualTo("FOO");
186193
}
187194

@@ -563,7 +570,7 @@ public Supplier<String> stringSupplier() {
563570

564571
@Bean
565572
public IntegrationFlow supplierFlow() {
566-
return IntegrationFlows.fromSupplier(stringSupplier())
573+
return IntegrationFlows.fromSupplier(stringSupplier(), c -> c.id("stringSupplierEndpoint"))
567574
.transform(toUpperCaseFunction())
568575
.channel("suppliedChannel")
569576
.get();

spring-integration-core/src/test/resources/META-INF/spring.integration.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#spring.integration.channels.maxBroadcastSubscribers=1
44
spring.integration.taskScheduler.poolSize=20
55
spring.integration.messagingTemplate.throwExceptionOnLateReply=true
6-
spring.integration.endpoints.noAutoStartup=fooService*
6+
spring.integration.endpoints.noAutoStartup=fooService*,stringSupplierEndpoint

0 commit comments

Comments
 (0)