2017-03-08 31 views
1

我有一個春季集成流,有一個服務激活器調用的網關服務,有一個無效的結果,它似乎掛起。它不會延續鏈條的其餘部分。我是否需要指定其他內容來表示我不希望從網關調用中返回結果來繼續執行線程?我有一個無效的方法聲明。春季集成鏈流 - 處理無效網關調用

服務

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.spr[email protected]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

好的。看,<chain>期望產品回覆中的所有組件移動到鏈中的下一個組件。前一個組件的回覆是鏈中下一個的輸入。所以,這真的是期望的,因爲你的網關不返回任何東西,沒有什麼可以發送給鏈中的下一個組件。

如果你真的不希望從網關得到答案,它就像「發送和忘記」一樣,請考慮切換到publish-subscribe-channel,將相同的消息發送到void網關,併發送到下一個組件主流。對,我們將不得不打破目前的鏈條,否則目前的做法將不會爲你工作。

+0

確定一切都必須有一個答覆才能成爲一個鏈。當它在void方法執行後向鏈的通道發送postSend時,它是否會打斷鏈並完成?它只是無視任何事後。 – haju

+0

如果網關下游的所有內容都在同一線程('DirectChannel's)上運行,那麼您可以將默認應答超時設置爲0,並且空結果將立即終止鏈,並且線程返回給調用者。由於定時器在線程返回到網關之前未啓動,因此它不會傷害收到答覆的情況。 –