春季集成-imap空闲接收器问题



我使用的是弹簧引导2.2.4-RELESE和弹簧集成。我正在开发一个简单的ImapReceiver。

我需要的是以下内容:

  • 我可以配置几个Imap侦听器(我使用spring集成DSL(
  • 我收到MimeMessage
  • 我得到了所有的信息和附件
  • 我通过将这些信息和附件放入数据库和Alfresco

我写了以下代码

ImapIdleChannelAdapterSpec imapIdleChannelAdapterSpec = Mail.imapIdleAdapter(connectionUrl.toString())
                    .javaMailProperties(javaMailProperties)
                    .shouldDeleteMessages(deleteMessages)
                    .shouldMarkMessagesAsRead(markMessagesRead)
                    .autoStartup(true)
                    .autoCloseFolder(true)
                    .id(confMailIn.getHost() + "_adapter")
                    .selector(selectFunction);
            if (confMailIn.isRichiedeAutenticazione()) {
                imapIdleChannelAdapterSpec = imapIdleChannelAdapterSpec.javaMailAuthenticator(new CasellaPostaleAuthenticator(cpd.getIndirizzoMail(), cpd.getUsername(), cpd.getPassword()));
            }
            flow = IntegrationFlows
                    .from(imapIdleChannelAdapterSpec)
                    .handle(message ->{
                        publishMailEvent(message);
                    })
                    .get();

publishMailEvent方法提取所有需要的信息(例如TO、CC、BCC、邮件主题、附件(,并生成一个自定义的spring-async事件。

现在,如果我离开autoCloseFolder(true),我就无法处理该消息,因为我得到了FolderClosedException。如果我设置autoCloseFolder(false),所有的工作,但我看到一个永无止境的打印

2020-03-06 10:24:37,580 141381 [asyncTaskExecutor-18] DEBUG i.e.t.r.p.w.b.h.MailMessageHandler - Header name Message-ID header value <opec292.20200306102349.32719.160.1.254.63@pec.aruba.it> 
2020-03-06 10:24:37,582 141383 [asyncTaskExecutor-12] TRACE i.e.t.r.p.w.b.h.MailMessageHandler - Aggiungo allegato smime.p7s all'elenco di allegati 
2020-03-06 10:24:37,583 141384 [asyncTaskExecutor-18] TRACE i.e.t.r.p.w.b.h.MailMessageHandler - Aggiungo allegato smime.p7s all'elenco di allegati 
2020-03-06 10:24:37,583 141384 [asyncTaskExecutor-15] TRACE i.e.t.r.p.w.b.h.MailMessageHandler - Aggiungo allegato smime.p7s all'elenco di allegati 
2020-03-06 10:24:37,607 141408 [asyncTaskExecutor-18] TRACE i.e.t.r.p.w.b.s.i.GestioneMailSvcImpl - Mail out con id messaggio <opec292.20200306102349.32719.160.1.254.63@pec.aruba.it> esistente ? false 
2020-03-06 10:24:37,607 141408 [asyncTaskExecutor-12] TRACE i.e.t.r.p.w.b.s.i.GestioneMailSvcImpl - Mail out con id messaggio <opec292.20200306102349.32719.160.1.63@pec.aruba.it> esistente ? false 
2020-03-06 10:24:37,607 141408 [asyncTaskExecutor-15] TRACE i.e.t.r.p.w.b.s.i.GestioneMailSvcImpl - Mail out con id messaggio <opec292.20200306102350.04933.324.2.326.71@pec.aruba.it> esistente ? false 
2020-03-06 17:19:33,850 140094 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:33,938 140182 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,021 140265 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,107 140351 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,190 140434 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,276 140520 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,362 140606 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,453 140697 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,537 140781 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,621 140865 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,703 140947 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,788 141032 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,874 141118 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,960 141204 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,051 141295 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,133 141377 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,216 141460 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,301 141545 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,386 141630 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,468 141712 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,553 141797 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,635 141879 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,718 141962 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,801 142045 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,885 142129 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:35,976 142220 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:36,062 142306 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:36,145 142389 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:36,233 142477 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:36,324 142568 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:36,410 142654 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:36,493 142737 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:36,574 142818 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:36,656 142900 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:36,743 142987 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:36,831 143075 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:36,918 143162 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,000 143244 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,083 143327 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,165 143409 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,247 143491 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,333 143577 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,431 143675 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,521 143765 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,609 143853 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,699 143943 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,806 144050 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,897 144141 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:37,993 144237 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:38,079 144323 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:38,181 144425 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:38,263 144507 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:38,346 144590 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 

此外,我不知道什么时候该关闭文件夹。我可以访问Closeable资源,但我应该何时关闭文件夹?如果我在事件生成后立即关闭它,那么在下一条消息中,我会再次收到FolderClosedException。

有人能给我一个建议,让我了解处理我需要的东西的最佳方法吗?

谢谢

Angelo

2020-03-06 17:19:33,938 140182 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 
2020-03-06 17:19:34,021 140265 [scheduling-1] INFO  o.s.i.mail.ImapMailReceiver - attempting to receive mail from folder [INBOX] 

这是ImapIdleChannelAdapter的正常行为,因为它是一个事件驱动的组件,并且基于计划任务。如果您想控制轮询逻辑,请考虑切换到常规MailReceivingMessageSource-Mail.imapInboundAdapter()

您确实无法在每条消息之后关闭文件夹。您应该在一段空闲时间内这样做,此时一段时间内没有新消息,下游也没有要处理的消息。

相关内容

  • 没有找到相关文章

最新更新