2016-09-28 2 views
0

재시도 메커니즘을 사용하여 SFTP 서버에 파일을 업로드하기 위해 스프링 SFTP 아웃 바운드 채널 어댑터를 사용하고 있습니다. 업로드에 오류가 발생하면 일정 횟수 재 시도 후 전자 메일을 보내고 오류 폴더로 이동합니다.스프링 통합 : failureChannel 문제

다음은 나의 구성입니다.

<file:inbound-channel-adapter id="csvFileChannel" 
    directory="${csv.base.directory}" filename-regex="^(.*).csv" 
    comparator="lastModifiedComparator" prevent-duplicates="true"> 
    <int:poller fixed-rate="5000" /> 
</file:inbound-channel-adapter> 

<bean id="lastModifiedComparator" 
    class="org.apache.commons.io.comparator.LastModifiedFileComparator" /> 
<bean id="sftpSessionFactory" 
    class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory" 
    lazy-init="true"> 
    <property name="host" value="${sftp.host}" /> 
    <property name="port" value="${sftp.port}" /> 
    <property name="user" value="${sftp.user}" /> 
    <property name="password" value="${sftp.password}" /> 
</bean> 

<int-sftp:outbound-channel-adapter 
    id="sftpOutboundAdapter" session-factory="sftpSessionFactory" channel="csvFileChannel" 
    remote-file-separator="/" remote-filename-generator-expression="payload.getName()" 
    remote-directory="/" mode="REPLACE"> 
    <int-sftp:request-handler-advice-chain> 
     <bean 
      class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice"> 
      <property name="onSuccessExpression" 
       value="payload.renameTo(new java.io.File('${csv.archive.directory}' , payload.name))" /> 
      <property name="successChannel" ref="nullChannel" /> 
      <property name="onFailureExpression" 
       value="payload.renameTo(new java.io.File('${csv.error.directory}' , payload.name))" /> 
      <property name="failureChannel" ref="failChannel" /> 
      <property name="trapException" value="true" /> 
     </bean> 
     <ref bean="retryAdvice" /> 
    </int-sftp:request-handler-advice-chain> 
</int-sftp:outbound-channel-adapter> 

<int:handler-retry-advice id="retryAdvice" 
    max-attempts="5"> 
    <int:fixed-back-off interval="5000" /> 
</int:handler-retry-advice> 

<int:channel id="failChannel" /> 

<int:chain input-channel="failChannel" output-channel="mailMessageChannel"> 
    <int:transformer 
     expression="'SFTP Upload failed for the file: ' + payload.failedMessage.payload.name " /> 
</int:chain> 
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl"> 
    <property name="host" value="${smtp.host}" /> 
    <property name="port" value="${smtp.port}" /> 
    <property name="username" value="${smtp.userName}" /> 
    <property name="password" value="${smtp.password}" /> 
    <property name="javaMailProperties"> 
     <props> 
      <prop key="mail.smtp.auth">true</prop> 
     </props> 
    </property> 
</bean> 

<int:channel id="mailMessageChannel" /> 
<int:chain input-channel="mailMessageChannel"> 
    <int-mail:header-enricher> 
     <int-mail:to value="${fail.email.to}" /> 
     <int-mail:cc value="${fail.email.to}" /> 
     <int-mail:from value="${fail.email.to}" /> 
     <int-mail:subject value="SFTP Upload failed" /> 
    </int-mail:header-enricher> 
    <int-mail:outbound-channel-adapter 
     mail-sender="mailSender" /> 
</int:chain> 

내가 직면 한 문제는 각 파일에 대해 2 개의 전자 메일을 받고 있다는 것입니다. 문제를 파악할 수 없습니다. spring-integration.logs

+0

'org.springframework.integration' 카테고리에'DEBUG' 로그를 공유하십시오. 'retryAdvice'없이 얼마나 많은 이메일을받을 수 있습니까? –

+0

@ArtemBilan : 스프링 통합 로그에 대한 링크를 제공했습니다. 'retryAdvice'없이 시도한 경우 2 개의 메일이 있습니다. – Vinod

답변

1

당신의 로그에 따르면, 우리는 소스 디렉토리에서 두 개의 파일이 있습니다 : 여기

봄 통합 로그입니다

그들 모두 마무리 이후 조금 혼란 어쩌면
2016-09-28 22:14:34,595 [DEBUG] [org.springframework.integration.file.FileReadingMessageSource] Added to queue: [D:\CSVFiles\MyCustomerTarget_20160928221429.csv, D:\CSVFiles\MyOrderTarget_20160928221429.csv] 

같은 접미사?

두 파일 모두 FTP로 전송하지 못했기 때문에 오류에 대한 두 가지 전자 메일이 있습니다. 각 파일마다 하나씩.

로그에 따라 더 이상 이메일을 보내지 않습니다.

아니요, 각 파일 당 2 개의 메일이 있습니다. 그래서, 총 4 개의 메일에 2 개의 파일이 있습니다.

글쎄, 한 번 더 설정을 살펴 보겠습니다.

<int-mail:to value="${fail.email.to}" /> 
<int-mail:cc value="${fail.email.to}" /> 
의 Gmail을 통해 나에게 두 개의 사본을 보내지 않습니다

하지만 다른 메일 서버가 동일한받는 사람에게이 전자 메일처럼 통과하지 않습니다 것을 의미하지 않는다.

+0

아니요, 각 파일 당 2 개의 메일이 있습니다. 그래서, 총 4 개의 메일에 2 개의 파일이 있습니다. – Vinod

+0

감사합니다. 그게 문제였습니다. 나는 to와 cc와 같은 이메일 id를 사용했다. – Vinod