Spring Integration Chain Flow - Handling Void Gateway Calls

ⅰ亾dé卋堺 提交于 2019-12-22 14:08:49

问题


I have a spring integration flow that has a service activator call to a gateway service that has a void result and it seems to hang. It doesn't continue the rest of the chain. Do I need to specify something else to say I don't expect a result return from my gateway call to continue thread execution? I have a void method declaration.

Service

package foo;

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


    public interface myService {


        void capitalString(String inputString ) ;

    }

Spring Integration Flow

    <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"/>-->

Debug Logs - It looks correct like it sends a reply. My file adapter doesn't seem to be called though.

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}]

回答1:


OK. Look, the <chain> expects that all components within produce reply to move to the next component in the chain. The reply of the previous component is an input for the next in the chain. So, that is really expected that since your gateway doesn't returns anything there is nothing to send to the next component in the chain.

If you really don't expect from the the gateway an answer and it is just like "send and forget", consider to switch to the publish-subscribe-channel to send the same message to the void gateway and to the next component in the main flow. Right, we will have to break your current chain, but otherwise the current approach won't work for you any way.



来源:https://stackoverflow.com/questions/42676147/spring-integration-chain-flow-handling-void-gateway-calls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!