Skip to content

Commit 1d769b8

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 37e6457 commit 1d769b8

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
@@ -63,6 +63,7 @@
6363
import org.springframework.integration.dsl.MessageChannels;
6464
import org.springframework.integration.dsl.Pollers;
6565
import org.springframework.integration.dsl.Transformers;
66+
import org.springframework.integration.endpoint.AbstractEndpoint;
6667
import org.springframework.integration.endpoint.EventDrivenConsumer;
6768
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
6869
import org.springframework.integration.handler.LoggingHandler;
@@ -178,8 +179,14 @@ public class IntegrationFlowTests {
178179
@Qualifier("lambdasInput")
179180
private MessageChannel lambdasInput;
180181

182+
@Autowired
183+
AbstractEndpoint stringSupplierEndpoint;
184+
181185
@Test
182186
public void testWithSupplierMessageSourceImpliedPoller() {
187+
assertThat(this.stringSupplierEndpoint.isAutoStartup()).isFalse();
188+
assertThat(this.stringSupplierEndpoint.isRunning()).isFalse();
189+
this.stringSupplierEndpoint.start();
183190
assertThat(this.suppliedChannel.receive(10000).getPayload()).isEqualTo("FOO");
184191
}
185192

@@ -540,7 +547,7 @@ public Supplier<String> stringSupplier() {
540547

541548
@Bean
542549
public IntegrationFlow supplierFlow() {
543-
return IntegrationFlows.from(stringSupplier())
550+
return IntegrationFlows.from(stringSupplier(), c -> c.id("stringSupplierEndpoint"))
544551
.transform(toUpperCaseFunction())
545552
.channel("suppliedChannel")
546553
.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)