【问题标题】:Spring Integration Chain Flow - Handling Void Gateway CallsSpring Integration Chain Flow - 处理无效网关调用
【发布时间】:2017-07-29 07:19:18
【问题描述】:

我有一个 spring 集成流程,它有一个服务激活器调用网关服务,该服务有一个无效的结果,它似乎挂起。它不会继续链条的其余部分。我是否需要指定其他内容来说明我不希望网关调用返回结果以继续线程执行?我有一个 void 方法声明。

服务

package foo;

import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.Payload;


    public interface myService {


        void capitalString(String inputString ) ;

    }

Spring 集成流程

    <import resource="classpath:META-INF/spring/integration/spring-integration-database-context.xml"/>
    <context:property-placeholder location="classpath:META-INF/spring/integration/testApp.properties"/>

    <!-- INTEGRATION FLOW - START -->   
    <int-file:inbound-channel-adapter 
            directory="file:${baseFilePath}\input" 
            id="filesInAdapter" 
            channel="inputChannel" 
            auto-startup="true">
        <int:poller fixed-delay="5000" />
    </int-file:inbound-channel-adapter>


    <int:channel id="inputChannel"/>

    <int:chain input-channel="inputChannel"  >

        <int:header-enricher id="fileNameHeaderEnricher" >
            <int:header name="fileName" expression="payload.getName()"></int:header>
        </int:header-enricher>      

        <int:service-activator  id="serviceActivator"  ref="myServiceGateway" method="capitalString"   />       

<!--write out the filename to the output file since void returns empty payload-->       
<int:transformer  id="payloadAppender" expression="headers['fileName']"/>

<int-file:outbound-channel-adapter  id="filesOut"  directory-expression=" '${defaultDirPath}' + 'Output\'" filename-generator-expression="'Output.txt'"  /></int:chain>
    <!-- INTEGRATION FLOW - END -->


    <int:channel id="capitalStringStoredChannel" />
    <int:gateway 
            id="myServiceGateway" 
            default-request-timeout="5000"
            default-reply-timeout="5000"
            default-request-channel="capitalStringStoredChannel"
            service-interface="foo.CaptialStringService" 
            error-channel="errorsProc">
            <int:method name="executeFoo"   request-channel="capitalStringStoredChannel" /> 
    </int:gateway>

    <!-- LOOK HERE MY GATEWAY -->
    <int-jdbc:stored-proc-outbound-gateway
        id="outbound-gateway-enroll"
        request-channel="capitalStringStoredChannel"
        data-source="dataSource"

        stored-procedure-name="CAPITALIZE_STRING"
        >
        <int-jdbc:parameter name="INOUTSTRING" expression="new java.lang.String(payload.split(',')[1])" />
    </int-jdbc:stored-proc-outbound-gateway>    

    <!--  <int:logging-channel-adapter id="loggit" log-full-message="true"/>-->

调试日志 - 看起来正确,就像它发送了回复一样。我的文件适配器似乎没有被调用。

11:46:19.830 DEBUG [task-scheduler-1][org.springframework.integration.handler.ServiceActivatingHandler] handler 'ServiceActivator for [org.springframework.integration.handler.MethodInvokingMessageProcessor@c406eb8a] (org.springframework.integration.handler.MessageHandlerChain#0$child.serviceActivator)' produced no reply for request Message: GenericMessage [payload=00111,123, headers={sequenceNumber=1, sequenceSize=0, correlationId=fa3a8e43-49b2-fd90-9aaa-ed02e15b260e,  FILE_NAME=file1_01.txt, timestamp=1488987979508}]
11:46:19.830 DEBUG [task-scheduler-1][org.springframework.integration.channel.DirectChannel] postSend (sent=true) on channel 'inputChannel', message: GenericMessage [payload=filename.txt, headers={id=904ee554-638d-eddf-efb5-7d4de30f4882, timestamp=1488987979489}]

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    好的。看,&lt;chain&gt; 期望生产中的所有组件都回复移动到链中的下一个组件。前一个组件的回复是链中下一个组件的输入。因此,由于您的网关没有返回任何内容,因此确实可以预期,因此没有任何内容可以发送到链中的下一个组件。

    如果您真的不希望网关给出答案并且它就像“发送并忘记”,请考虑切换到publish-subscribe-channel 将相同的消息发送到void 网关并发送到下一个主流程中的组成部分。是的,我们将不得不打破您当前的链条,否则当前的方法对您不起作用。

    【讨论】:

    • 好的,一切都必须有回复才能进入链条。当它在 void 方法执行后向链的通道发送 postSend 时,是否打破了链并完成?它只是忽略之后的任何内容。
    • 如果网关下游的所有东西都运行在同一个线程上(DirectChannels),那么您可以将默认回复超时设置为 0,null 结果将立即终止链,线程返回到呼叫者。收到回复时不会影响条件,因为在线程返回网关之前不会启动计时器。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-11
    • 2012-10-16
    • 2017-03-07
    • 1970-01-01
    相关资源
    最近更新 更多