2012-06-07 3 views
2

우리는 Spring Integration 2.1.1을 사용하여 트랜잭션으로 POP3 메일 박스에서 메일을 읽으려고합니다. 트랜잭션 성은 전자 메일 메시지를 읽고이를 Oracle에 보관하고 사서함에서 제거 할 수 있도록하기위한 것입니다. 트랜잭션 롤백이 발생하면 이메일이 사서함에 남아 있기를 원합니다 (즉, 삭제되지 않음).Spring 통합을 사용한 트랜잭션 POP3 메일 박스 액세스

우리의 문제는 트랜잭션 (초에 대한 자세한 내용)에도 불구하고 메일 상자가 열리고 메일이 검색되고 삭제 표시가되어 트랜잭션의 나머지 부분과 관계없이 연결이 닫힙니다. 즉, 나중에 연결이 끊어지고 메일 함이 영구적으로 이메일을 삭제하는 UPDATE 상태가되면 메일이 삭제되지 않는 경우 메일을 삭제하지 못하는 것입니다. 차례에

가 듣고 : 인바운드 이메일 채널에 메시지를두고

<!-- This inbound channel adaptor interfaces to the sendmail POP3 queue --> 
<int-mail:inbound-channel-adapter id="pop3PollingChannelAdaptor" 
            store-uri="pop3://myuser:[email protected]/inbox" 
            channel="receiveInboundEmailChannel" 
            should-delete-messages="true"    
            auto-startup="true" 
            java-mail-properties="javaMailProperties"> 
    <!-- Will poll every 20 seconds -->    
    <int:poller fixed-rate="10000" 
       max-messages-per-poll="1"> 
     <int:transactional transaction-manager="txManager" 
          isolation="DEFAULT" 
          propagation="REQUIRED" 
          read-only="false" 
          timeout="100000" /> 
    </int:poller> 
</int-mail:inbound-channel-adapter> 

: 우리는 트랜잭션 폴링 인바운드 채널 어댑터를 작성하여이 작업을 수행하려고 시도했습니다

아웃 바운드 채널 어댑터 (엔드 포인트) :

<int:outbound-channel-adapter channel="receiveInboundEmailChannel" 
           ref="inboundEmailMessageEndpoint" 
           method="processMessage" /> 

현재 엔드 포인트 구현은 현재 상황을 매우 간단하게 유지합니다. 우리는 현재 데이터베이스 근처에서 아무 것도하지 않습니다. 대신 롤백을 트리거하려면 예외가 발생합니다. 모든 로그를 보면

@MessageEndpoint 
public class InboundEmailMessageEndpoint { 
    @Transactional(propagation = Propagation.MANDATORY) 
    public void processMessage(Message<MimeMessage> message) { 

     MimeMessage mailMessage = message.getPayload(); 

     // We throw exceptions here to cause a rollback if we need to during investigation... 
    } 
} 

, 우리는 (주의 맥락에서 우리의 문제를 볼 수있는 방법 POP3 "사요 나라의"엔드 포인트에있는 우리의 나머지 작업을 시작하기 전에, 그리고 가장 중요한 것은, 주위의 트랜잭션이 커밋하기 전에/롤 back) :

15:32:25.256 INFO [main][org.springframework.transaction.jta.JtaTransactionManager]  Using JTA UserTransaction: [email protected] 
15:32:25.256 INFO [main][org.springframework.transaction.jta.JtaTransactionManager] Using JTA TransactionManager: [email protected] 
15:32:25.422 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] getCompositeTransaction() returning NULL! 
15:32:25.422 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] getCompositeTransaction() returning NULL! 
15:32:25.423 DEBUG [task-scheduler-1][org.springframework.transaction.jta.JtaTransactionManager] Creating new transaction with name [org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,timeout_100000 
15:32:25.423 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] getCompositeTransaction() returning NULL! 
15:32:25.423 WARN [task-scheduler-1][com.atomikos.icatch.imp.TransactionServiceImp] Attempt to create a transaction with a timeout that exceeds com.atomikos.icatch.max_timeout - truncating to: 300000 
15:32:25.423 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.CoordinatorImp] Coordinator 10.9.21.7.tm0000100022 entering state: ACTIVE 
15:32:25.425 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.thread.TaskManager] TaskManager: initializing... 
15:32:25.426 INFO [task-scheduler-1][com.atomikos.icatch.imp.thread.TaskManager] THREADS: using JDK thread pooling... 
15:32:25.428 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.thread.TaskManager] THREADS: using executor class com.atomikos.icatch.imp.thread.Java15ExecutorFactory$Executor 
15:32:25.428 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.thread.Java15ExecutorFactory] (1.5) executing task: [email protected] 
15:32:25.429 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.thread.ThreadFactory] ThreadFactory: creating new thread: Atomikos:0 
15:32:25.429 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.TransactionServiceImp] Creating composite transaction: 10.9.21.7.tm0000100022 
15:32:25.433 INFO [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] createCompositeTransaction (100000000): created new ROOT transaction with id 10.9.21.7.tm0000100022 
DEBUG: JavaMail version 1.4.4 
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers 
DEBUG: Tables of loaded providers 
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc]} 
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Sun Microsystems, Inc], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Sun Microsystems, Inc], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]} 
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map 
DEBUG: getProvider() returning javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Sun Microsystems, Inc] 
DEBUG POP3: mail.pop3.rsetbeforequit: false 
DEBUG POP3: mail.pop3.disabletop: false 
DEBUG POP3: mail.pop3.forgettopheaders: false 
DEBUG POP3: mail.pop3.cachewriteto: false 
DEBUG POP3: mail.pop3.filecache.enable: false 
DEBUG POP3: mail.pop3.keepmessagecontent: false 
DEBUG POP3: mail.pop3.starttls.enable: false 
DEBUG POP3: mail.pop3.starttls.required: false 
15:32:25.446 DEBUG [task-scheduler-1][org.springframework.integration.mail.Pop3MailReceiver] connecting to store [pop3://devmail9:*****@100.100.100.100/inbox] 
DEBUG POP3: mail.pop3.apop.enable: false 
DEBUG POP3: mail.pop3.disablecapa: false 
DEBUG POP3: connecting to host "100.100.100.100", port 110, isSSL false 
S: +OK POP3 xxxxx.xxxx.xxxx.xxx.xxx.uk v4.39 server ready 
C: CAPA 
S: -ERR Unknown command in AUTHORIZATION state 
C: USER myuser 
S: +OK User name accepted, password please 
C: PASS myuser 
S: +OK Mailbox open, 3 messages 
15:32:25.564 DEBUG [task-scheduler-1][org.springframework.integration.mail.Pop3MailReceiver] opening folder [pop3://myuser:*****@100.100.100.100/inbox] 
C: STAT 
S: +OK 3 5956 
15:32:25.569 INFO [task-scheduler-1][org.springframework.integration.mail.Pop3MailReceiver] attempting to receive mail from folder [inbox] 
C: NOOP 
S: +OK No-op to you too! 
15:32:25.591 DEBUG [task-scheduler-1][org.springframework.integration.mail.Pop3MailReceiver] found 1 new messages 
C: TOP 1 0 
S: +OK Top of message follows 
Received: from xxxxx.xxxx.xxxx.xxx.xxx.uk ([100.100.100.100]) by  xxxxx.xxxx.xxxx.xxx.xxx.uk (AIX5.2/8.11.6p2/8.11.0) with ESMTP id q57EUrG1544330 for C: LIST 1 

.... 

S: +OK 1 1996 
15:32:25.604 DEBUG [task-scheduler-1][org.springframework.integration.mail.Pop3MailReceiver] Recieved 1 messages 
15:32:26.097 DEBUG [task-scheduler-1][org.springframework.integration.mail.Pop3MailReceiver] USER flags are not supported by this mail server. Flagging message with system flag 
DEBUG POP3: streaming msg 1 
C: RETR 1 
S: +OK 1996 octets 
Received: from xxxxx.xxxx.xxxx.xxx.xxx.uk ([100.100.100.100]) by GLA610.crown.copfs.gsi.gov.uk (AIX5.2/8.11.6p2/8.11.0) with ESMTP id q57EUrG1544330 for <[email protected]>; Thu, 7 Jun 2012 15:30:53 +0100 

.... 

DEBUG POP3: streaming msg 1 
C: RETR 1 
S: +OK 1996 octets 
Received: from xxxxx.xxxx.xxxx.xxx.xxx.uk ([100.100.100.100]) by xxxxx.xxxx.xxxx.xxx.xxx.uk (AIX5.2/8.11.6p2/8.11.0) with ESMTP id q57EUrG1544330 for <[email protected]>; Thu, 7 Jun 2012 15:30:53 +0100 

.... 

. 
C: NOOP 
S: +OK No-op to you too! 
C: DELE 1 
S: +OK Message deleted 
C: QUIT 
S: +OK Sayonara 
15:32:26.672 DEBUG [task-scheduler-1][org.springframework.integration.mail.MailReceivingMessageSource] received mail message [[email protected]] 
15:32:26.696 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] getCompositeTransaction() returning instance with id 10.9.21.7.tm0000100022 
15:32:26.697 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] getCompositeTransaction() returning instance with id 10.9.21.7.tm0000100022 
15:32:26.697 DEBUG [task-scheduler-1][org.springframework.transaction.jta.JtaTransactionManager] Participating in existing transaction 
15:32:26.716 INFO [task-scheduler-1][xx.xxx.xxx.xxx.channel.email.InboundEmailMessageEndpoint] In InboundEmailMessageEndpoint. processing MailMessage (Subject): 7777777777777777777 
15:32:26.735 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] getCompositeTransaction() returning instance with id 10.9.21.7.tm0000100022 
15:32:26.735 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] getCompositeTransaction() returning instance with id 10.9.21.7.tm0000100022 
15:32:26.735 DEBUG [task-scheduler-1][org.springframework.transaction.jta.JtaTransactionManager] Initiating transaction commit 
15:32:26.735 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] getCompositeTransaction() returning instance with id 10.9.21.7.tm0000100022 
15:32:26.735 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] getCompositeTransaction() returning instance with id 10.9.21.7.tm0000100022 
15:32:26.735 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] getCompositeTransaction() returning instance with id 10.9.21.7.tm0000100022 
15:32:26.735 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.BaseTransactionManager] getCompositeTransaction() returning instance with id 10.9.21.7.tm0000100022 
15:32:26.736 INFO [task-scheduler-1][com.atomikos.icatch.imp.CompositeTransactionImp] commit() done (by application) of transaction 10.9.21.7.tm0000100022 
15:32:26.736 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.CoordinatorImp] Coordinator 10.9.21.7.tm0000100022 entering state: COMMITTING 
15:32:26.740 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.CoordinatorImp] Coordinator 10.9.21.7.tm0000100022 entering state: TERMINATED 
15:32:26.741 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.CoordinatorImp] Coordinator 10.9.21.7.tm0000100022 : stopping timer... 
15:32:26.741 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.CoordinatorImp] Coordinator 10.9.21.7.tm0000100022 : disposing statehandler TERMINATED... 
15:32:26.741 DEBUG [task-scheduler-1][com.atomikos.icatch.imp.CoordinatorImp] Coordinator 10.9.21.7.tm0000100022 : disposed. 

답변

0

POP3는 트랜잭션이지만 데이터베이스 및 메시지 큐 트랜잭션은 아닙니다. 결과적으로, 우리가 필요로하는대로 거래에 제대로 참여할 수 없습니다.

그러나 Spring 통합 팀은 "Best Efforts 1PC"패턴의 라인을 따라 pseudo-transactional 지원을 추가하고 POP3 "commit"을 마지막 단계로 추가합니다. 이것은 2.2.0 릴리스로 만들 것 인 것처럼 보입니다.

+0

필자는 매우 비슷한 요구 사항을 가지고 있지만 POP3 대신 IMAP을 사용하고 있습니다. 동일한 시도를 해봤지만 작동하지 않습니다. IMAP에도 동일한 문제가 있습니까? – Mahendran

0

메일 서버는 트랜잭션을 지원하지 않습니다. 트랜잭션/인 텐트 로그, 장애 복구 등 메일 서버를 래핑하기 위해 자신의 트랜잭션 리소스를 구현해야합니다.