GH-8577: Revise ImapIdleChannelAdapter logic (#8588)

* GH-8577: Revise `ImapIdleChannelAdapter` logic

Fixes https://github.com/spring-projects/spring-integration/issues/8577

When we process mail messages in async manner, it is possible that we end up
in a race condition situation where the next idle cycle closes the folder.

It is possible to reopen the folder, but feels better to block the current idle
cycle until we are done with the message and therefore keep folder opened.

* Deprecate `ImapIdleChannelAdapter.sendingTaskExecutor` in favor of an `ExecutorChannel`
as an output for this channel adapter or similar async hand-off downstream.
* Make use of `shouldReconnectAutomatically` as it is advertised for this channel adapter
* Optimize the proxy creation for message sending task

* * Remove `ImapIdleChannelAdapter.sendingTaskExecutor`

* Fix language in docs

Co-authored-by: Gary Russell <grussell@vmware.com>

---------

Co-authored-by: Gary Russell <grussell@vmware.com>
This commit is contained in:
Artem Bilan
2023-03-29 10:15:47 -04:00
committed by GitHub
parent 22d47e72e9
commit 4fdbdf180e
9 changed files with 125 additions and 131 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-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.
@@ -209,6 +209,7 @@ public class ImapMailReceiverTests {
adapter.setOutputChannel(channel);
adapter.setTaskScheduler(taskScheduler);
adapter.setReconnectDelay(1);
adapter.afterPropertiesSet();
adapter.start();
MimeMessage message =
GreenMailUtil.createTextEmail("Foo <foo@bar>", "Bar <bar@baz>", "Test Email", "foo\r\n",
@@ -698,6 +699,7 @@ public class ImapMailReceiverTests {
QueueChannel channel = new QueueChannel();
adapter.setOutputChannel(channel);
adapter.setReconnectDelay(1);
adapter.afterPropertiesSet();
ImapMailReceiver receiver = new ImapMailReceiver("imap:foo");
receiver.setCancelIdleInterval(1);

View File

@@ -78,8 +78,7 @@
store-uri="imap:foo"
channel="channel"
auto-startup="false"
should-delete-messages="true"
task-executor="executor">
should-delete-messages="true">
<mail:transactional synchronization-factory="syncFactory" />
</mail:imap-idle-channel-adapter>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-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.
@@ -194,7 +194,6 @@ public class ImapIdleChannelAdapterParserTests {
assertThat(receiverAccessor.getPropertyValue("shouldDeleteMessages")).isEqualTo(Boolean.TRUE);
assertThat(receiverAccessor.getPropertyValue("shouldMarkMessagesAsRead")).isEqualTo(Boolean.TRUE);
assertThat(adapterAccessor.getPropertyValue("errorChannel")).isNull();
assertThat(adapterAccessor.getPropertyValue("sendingTaskExecutor")).isEqualTo(context.getBean("executor"));
assertThat(adapterAccessor.getPropertyValue("adviceChain")).isNotNull();
}