Spring Integration锁忙,另一个会话处于活动状态

时间:2016-08-10 17:39:09

标签: java spring spring-integration

我正在使用Spring Integration连接到POP3收件箱(不幸的是,它不支持IMAP)。这是我的配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
    http://www.springframework.org/schema/integration/mail http://www.springframework.org/schema/integration/mail/spring-integration-mail.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
  xmlns:int="http://www.springframework.org/schema/integration"
  xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
  xmlns:util="http://www.springframework.org/schema/util">

  <int:channel id="mailInputChannel"  />
  <int:channel id="channel1" />
  <int:channel id="channel2" />
  <int:channel id="discardChannel" />

  <!-- replace 'userid and 'password' with the real values -->
  <int-mail:inbound-channel-adapter id="pop3ShouldDeleteTrue"
                      store-uri="pop3://userid:password@host.example.com/Inbox"
                  channel="mailInputChannel"
                  should-delete-messages="true"
                  auto-startup="true"
                  java-mail-properties="javaMailProperties">

    <!-- Will poll every 1 seconds -->
    <int:poller max-messages-per-poll="1000" fixed-delay="1000"/>

  </int-mail:inbound-channel-adapter>

  <int:recipient-list-router id="incomingMailRouter" input-channel="mailInputChannel">
    <int:recipient channel="channel1" selector-expression="payload.subject matches '^.*channel1.*$'"/>
    <int:recipient channel="channel2" selector-expression="payload.subject matches '^.*channel2.*$'"/>
  </int:recipient-list-router>      

  <util:properties id="javaMailProperties">
    <prop key="mail.pop3.socketFactory.fallback">false</prop>
    <prop key="mail.debug">false</prop>
  </util:properties>
</beans>

基本上我有一个inbound-channel-adapter来读取消息,还有一个简单的recipient-list-router来指导它。

当我启动应用程序时,它运行正常。但是,在处理完第一封电子邮件后,它有时会挂起。调试输出是:

19260 [task-scheduler-1] DEBUG org.springframework.integration.mail.Pop3MailReceiver  - connecting to store [pop3://username:password@mailhost.example.com/Inbox]
DEBUG POP3: mail.pop3.apop.enable: false
DEBUG POP3: mail.pop3.disablecapa: false
DEBUG POP3: connecting to host "mailhost.example.com", port 110, isSSL false
+OK Qpopper (version 4.0.5) at cobweb starting.  
CAPA
+OK Capability list follows
TOP
USER
LOGIN-DELAY 0
EXPIRE 0
UIDL
RESP-CODES
AUTH-RESP-CODE
X-MANGLE
X-MACRO
X-LOCALTIME Wed, 10 Aug 2016 11:50:57 -0700
IMPLEMENTATION Qpopper-version-4.0.5
.
DEBUG POP3: authentication command trace suppressed
DEBUG POP3: authentication command failed
QUIT
+OK Pop server at cobweb signing off.
30529 [task-scheduler-1] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory  - Returning cached instance of singleton bean 'errorChannel'
30531 [task-scheduler-1] DEBUG org.springframework.integration.channel.PublishSubscribeChannel  - preSend on channel 'errorChannel', message: ErrorMessage [payload=org.springframework.messaging.MessagingException: failure occurred while polling for mail; nested exception is javax.mail.AuthenticationFailedException: [IN-USE] /var/spool/maildrop/.program_name.pop lock busy!  Is another session active? (11), headers={id=43817279-7717-f4d7-971a-3c283e2dbec3, timestamp=1470849586452}]
30531 [task-scheduler-1] DEBUG org.springframework.integration.handler.LoggingHandler  - _org.springframework.integration.errorLogger.handler received message: ErrorMessage [payload=org.springframework.messaging.MessagingException: failure occurred while polling for mail; nested exception is javax.mail.AuthenticationFailedException: [IN-USE] /var/spool/maildrop/.program_name.pop lock busy!  Is another session active? (11), headers={id=43817279-7717-f4d7-971a-3c283e2dbec3, timestamp=1470849586452}]
30534 [task-scheduler-1] ERROR org.springframework.integration.handler.LoggingHandler  - org.springframework.messaging.MessagingException: failure occurred while polling for mail; nested exception is javax.mail.AuthenticationFailedException: [IN-USE] /var/spool/maildrop/.program_name.pop lock busy!  Is another session active? (11)
  at org.springframework.integration.mail.MailReceivingMessageSource.receive(MailReceivingMessageSource.java:131)
  at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:209)
  at org.springframework.integration.endpoint.AbstractPollingEndpoint.doPoll(AbstractPollingEndpoint.java:245)
  at org.springframework.integration.endpoint.AbstractPollingEndpoint.access$000(AbstractPollingEndpoint.java:58)
  at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:190)
  at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:186)
  at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:353)
  at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:55)
  at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
  at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:51)
  at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:344)
  at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
  at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
  at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
  at java.util.concurrent.FutureTask.run(Unknown Source)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
Caused by: javax.mail.AuthenticationFailedException: [IN-USE] /var/spool/maildrop/.program_name.pop lock busy!  Is another session active? (11)
  at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:207)
  at javax.mail.Service.connect(Service.java:295)
  at javax.mail.Service.connect(Service.java:176)
  at javax.mail.Service.connect(Service.java:125)
  at org.springframework.integration.mail.AbstractMailReceiver.connectStoreIfNecessary(AbstractMailReceiver.java:286)
  at org.springframework.integration.mail.AbstractMailReceiver.openFolder(AbstractMailReceiver.java:297)
  at org.springframework.integration.mail.AbstractMailReceiver.receive(AbstractMailReceiver.java:319)
  at org.springframework.integration.mail.MailReceivingMessageSource.receive(MailReceivingMessageSource.java:112)
  ... 19 more

它会在这个循环中停留一段(看似)随机的时间,有时长达2分钟,每次尝试连接时都会吐出这些异常。但是,有时它会在处理消息后立即连接文件。处理消息是导致其失败的唯一因素。

Spring是否试图长时间保持与该连接的连接?我可以告诉它在收到电子邮件后立即断开连接吗?

1 个答案:

答案 0 :(得分:0)

原来这是一个服务器端问题。切换到支持IMAP的生产级邮件服务器后,问题得以解决。