2017-09-05 45 views
0

我使用Spring集成將消息聚合爲一個,然後通過FTP發送綁定適配器,我想在出站FTP服務器不可用時將聚合消息移動到特定文件夾中org.springframework.messaging.MessageDeliveryException),其他異常將通過控制檯記錄。如何在聚合器後定義鏈中的異常路由器

這裏是我的配置

<int:chain id="transformChain" input-channel="inboundChannel"> 
    <int:header-enricher> 
     <int:header name="file_name" expression="payload.name"/> 
     <int:header name="correlationId" expression="${header.enricher.correlationId}"/> 
     <int:header name="sum" expression="${header.enricher.sum}"/> 
    </int:header-enricher> 

    <int:transformer ref="fileNameToContentTransformer"/> 

    <int:aggregator send-partial-result-on-expiry="true" 
        release-strategy-expression="#this.size() == new Integer([0].headers.sum)" 
        group-timeout="${aggregator.group-timeout}" 
        message-store="messageStore" 
        expire-groups-upon-completion="true" 
        correlation-strategy-expression="headers.correlationId"/> 
    <int:transformer ref="xmlToJsonTransformer"/> 
    <ftp:outbound-channel-adapter remote-directory="${ftp.out.remote.directory}" 
            session-factory="ftpOutClientSessionFactory" auto-create-directory="true" 
            remote-filename-generator="fileNameGenerator" charset="UTF-8" 
            temporary-file-suffix=".writing"> 
    </ftp:outbound-channel-adapter> 

    <int:exception-type-router > 
     <int:mapping exception-type="org.springframework.messaging.MessageDeliveryException" channel="undeliveredChannel"/> 
     <int:mapping exception-type="java.lang.Exception" channel="myErrorChannel"/> 
    </int:exception-type-router> 
</int:chain> 

但是我遇到了異常,當嘗試啓動。

Caused by: java.lang.IllegalArgumentException: All handlers except for the last one in the chain must implement the MessageProducer interface. Object of class [org.springframework.integration.ftp.outbound.FtpMessageHandler] must be an instance of interface org.springframework.integration.core.MessageProducer 
at org.springframework.util.Assert.instanceCheckFailed(Assert.java:389) 
at org.springframework.util.Assert.isInstanceOf(Assert.java:327) 
at org.springframework.integration.handler.MessageHandlerChain.configureChain(MessageHandlerChain.java:119) 
at org.springframework.integration.handler.MessageHandlerChain.onInit(MessageHandlerChain.java:99) 
at org.springframework.integration.context.IntegrationObjectSupport.afterPropertiesSet(IntegrationObjectSupport.java:176) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) 

任何人都可以告訴我如何做到這一點? 在此先感謝。

回答

1

您不能在ftp:outbound-channel-adapter之後將組件添加到鏈中,因爲它不會產生任何結果。

有關如何通過向出站適配器添加ExpressionEvaluatingRequestHandlerAdvice來處理異常的示例,請參閱retry-and-more sample

相關問題