В моем проекте я использую адаптер холостого хода imap со следующей конфигурацией:
@Bean
public IntegrationFlow imapAdapter(MailNotifierProperties properties, SubscribableChannel errorChannel,
SubscribableChannel incomingMailChannel) {
return from(Mail.imapIdleAdapter(properties.getImapUrl())
.javaMailProperties(p -> p
.put("mail.imap.starttls.enable", "true")
.put("mail.imap.ssl.trust", "*"))
.errorChannel(errorChannel)
.shouldDeleteMessages(properties.getDeleteMessages()))
.channel(incomingMailChannel)
.get();
}
Конфигурация работает нормально большую часть времени.Но один или два раза в день я получаю следующее исключение, и приложение не может обрабатывать почту в течение примерно 30 минут:
2018-11-18 07:05:45.342 WARN 19778 --- [TaskScheduler19] o.s.i.mail.ImapIdleChannelAdapter : error occurred in idle task
javax.mail.MessagingException: * NO Mailbox is locked, will abort in 268 seconds
at com.sun.mail.imap.IMAPFolder.handleIdle(IMAPFolder.java:3201) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3043) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:2995) ~[javax.mail-1.5.5.jar!/:1.5.5]
at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:175) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:271) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:241) [spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) [spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_121]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: com.sun.mail.iap.CommandFailedException: * NO Mailbox is locked, will abort in 268 seconds
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:396) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.protocol.IMAPProtocol.processIdleResponse(IMAPProtocol.java:3225) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.IMAPFolder.handleIdle(IMAPFolder.java:3173) ~[javax.mail-1.5.5.jar!/:1.5.5]
... 14 common frames omitted
2018-11-18 07:05:45.343 WARN 19778 --- [TaskScheduler19] o.s.i.mail.ImapIdleChannelAdapter : Failed to execute IDLE task. Will attempt to resubmit in 10000 milliseconds.
java.lang.IllegalStateException: Failure in 'idle' task. Will resubmit.
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:290) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:241) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) [spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_121]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: javax.mail.MessagingException: * NO Mailbox is locked, will abort in 268 seconds
at com.sun.mail.imap.IMAPFolder.handleIdle(IMAPFolder.java:3201) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:3043) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.IMAPFolder.idle(IMAPFolder.java:2995) ~[javax.mail-1.5.5.jar!/:1.5.5]
at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:175) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:271) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
... 10 common frames omitted
Caused by: com.sun.mail.iap.CommandFailedException: * NO Mailbox is locked, will abort in 268 seconds
at com.sun.mail.iap.Protocol.handleResult(Protocol.java:396) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.protocol.IMAPProtocol.processIdleResponse(IMAPProtocol.java:3225) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.IMAPFolder.handleIdle(IMAPFolder.java:3173) ~[javax.mail-1.5.5.jar!/:1.5.5]
... 14 common frames omitted
2018-11-18 07:36:51.824 WARN 19778 --- [TaskScheduler19] o.s.i.mail.ImapIdleChannelAdapter : error occurred in idle task
javax.mail.FolderClosedException: * BYE Disconnected for inactivity.
at com.sun.mail.imap.IMAPFolder.throwClosedException(IMAPFolder.java:3601) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.IMAPFolder.doCommand(IMAPFolder.java:3737) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.IMAPFolder.exists(IMAPFolder.java:583) ~[javax.mail-1.5.5.jar!/:1.5.5]
at org.springframework.integration.mail.AbstractMailReceiver.openFolder(AbstractMailReceiver.java:299) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:158) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:271) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:241) [spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) [spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_121]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
2018-11-18 07:36:51.824 WARN 19778 --- [TaskScheduler19] o.s.i.mail.ImapIdleChannelAdapter : Failed to execute IDLE task. Will attempt to resubmit in 10000 milliseconds.
java.lang.IllegalStateException: Failure in 'idle' task. Will resubmit.
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:290) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$ReceivingTask.run(ImapIdleChannelAdapter.java:241) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81) [spring-context-4.3.3.RELEASE.jar!/:4.3.3.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_121]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_121]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: javax.mail.FolderClosedException: * BYE Disconnected for inactivity.
at com.sun.mail.imap.IMAPFolder.throwClosedException(IMAPFolder.java:3601) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.IMAPFolder.doCommand(IMAPFolder.java:3737) ~[javax.mail-1.5.5.jar!/:1.5.5]
at com.sun.mail.imap.IMAPFolder.exists(IMAPFolder.java:583) ~[javax.mail-1.5.5.jar!/:1.5.5]
at org.springframework.integration.mail.AbstractMailReceiver.openFolder(AbstractMailReceiver.java:299) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.integration.mail.ImapMailReceiver.waitForNewMessages(ImapMailReceiver.java:158) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
at org.springframework.integration.mail.ImapIdleChannelAdapter$IdleTask.run(ImapIdleChannelAdapter.java:271) ~[spring-integration-mail-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
... 10 common frames omitted
2018-11-18 07:37:01.872 INFO 19778 --- [TaskScheduler19] o.s.integration.mail.ImapMailReceiver : attempting to receive mail from folder [INBOX]
Сейчас у меня нет ответов на следующие вопросы 1) Что вызываетсообщение об ошибке: «* НЕТ Почтовый ящик заблокирован, будет отменен через 268 секунд»?2) Почему в течение следующих 30 минут не было обработано писем?
Обновление: Я проверил файлы журналов на сервере и смог найти следующее сообщение, которое появляется одновременновремя:
Nov 18 07:05:33 MailServer postfix/local[19960]: 5D5AAC20FA: to=<sender@domain.com>, orig_to=<recipient@domain.com>, relay=local, delay=19, delays=0.01/0/0/19, dsn=4.2.0, status=deferred (cannot update mailbox /var/mail/mailUser for user mailUser. unable to lock for exclusive access: Resource temporarily unavailable)
Однако файл, блокирующий почтовый ящик, удаляется через 30 секунд.
Существует ли способ настроить адаптер канала imap на повторное подключение в более короткий период.У меня все еще есть проблема, что приложение ждет 30 минут для повторного подключения к почтовому ящику.