Fix maxMessagesPerPoll for SourcePollingChAdapter (#8747)

* Fix maxMessagesPerPoll for SourcePollingChAdapter

The `AbstractMethodAnnotationPostProcessor` does not check
for `PollerMetadata.MAX_MESSAGES_UNBOUNDED` before setting
`maxMessagesPerPoll` into a `SourcePollingChannelAdapter`
which in this case must be `1`

Also fix `SourcePollingChannelAdapterFactoryBean` to not mutate
the provided `PollerMetadata` (which might be global default)
with a new `maxMessagesPerPoll`

**Cherry-pick to `6.1.x` & `6.0.x`**

* * Fix `this.` prefix in `SourcePollingChannelAdapterFactoryBean`
This commit is contained in:
Artem Bilan
2023-10-04 11:49:28 -04:00
committed by GitHub
parent 261589a417
commit ad01c44980
3 changed files with 18 additions and 6 deletions

View File

@@ -105,6 +105,7 @@ import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.endpoint.MethodInvokingMessageSource;
import org.springframework.integration.endpoint.PollingConsumer;
import org.springframework.integration.endpoint.ReactiveStreamsConsumer;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.expression.SpelPropertyAccessorRegistrar;
import org.springframework.integration.gateway.GatewayProxyFactoryBean;
import org.springframework.integration.handler.ServiceActivatingHandler;
@@ -417,12 +418,15 @@ public class EnableIntegrationTests {
assertThat(this.counterChannel.receive(10)).isNull();
SmartLifecycle countSA = this.context.getBean("annotationTestService.count.inboundChannelAdapter",
SmartLifecycle.class);
SourcePollingChannelAdapter countSA =
this.context.getBean("annotationTestService.count.inboundChannelAdapter",
SourcePollingChannelAdapter.class);
assertThat(countSA.isAutoStartup()).isFalse();
assertThat(countSA.getPhase()).isEqualTo(23);
countSA.start();
assertThat(countSA.getMaxMessagesPerPoll()).isEqualTo(1);
for (int i = 0; i < 10; i++) {
Message<?> message = this.counterChannel.receive(10_000);
assertThat(message).isNotNull();