2017-01-17 27 views
1

我在我的應用程序中收到一個錯誤,我沒有得到解決方案。 應用程序請求REST/JSON並嘗試與其他應用程序通信。有一個輪詢器異步調用每個請求。 執行請求時,總是調度錯誤「no output-channel or replyChannel header available」,並將其重定向到errorChannel句柄。HttpRequestExecutingMessageHandler:沒有output-channel或replyChannel頭可用

... 
@Bean(name = PollerMetadata.DEFAULT_POLLER) 
public PollerMetadata poller() { 
    return Pollers    
      .fixedRate(NumberUtils.createLong(QUEUE_RATE)) 
      .get(); 
} 

    @Bean 
public MessageChannel errorChannel() { 
    return MessageChannels.direct().get(); 
} 

    @MessagingGateway 
public static interface HttpService { 
    @Gateway(requestChannel = "service.input") 
    void send(@Payload String body, @Headers MultiValueMap<String, String> headers);   
} 


public MessageHandler httpOutboundAdapter(){ 
    HttpRequestExecutingMessageHandler handler = 
      Http.outboundGateway(URI, restTemplate)    
      .expectedResponseType(String.class)   
      .httpMethod(HttpMethod.POST) 
      .mappedRequestHeaders("Authorization","Accept","Content-Type", "X-User-Email","X-User-Token")    
      .get(); 

    return handler; 
} 


@Bean 
public FileWritingMessageHandler fileOutboundAdapter(){ 
    FileWritingMessageHandler fwmhs = Files 
      .outboundAdapter(new File("logs/errors")) 
      .autoCreateDirectory(true) 
      .get();  

    return fwmhs; 
} 

    @Bean 
public IntegrationFlow send(){ 
    return IntegrationFlows.from("service.input") 
      .log(Level.DEBUG, "trace.http", 
        "'Request.\n'"+ 
        ".concat('Headers : ').concat(headers.toString()).concat('\n')"+ 
        ".concat('Payload : ').concat(payload.toString())" 
       )        
      .channel(MessageChannels.queue()) 
      .handle(this.httpOutboundAdapter() 
      .transform(Transformers.toJson()) 
      .log(Level.DEBUG, "trace.http", 
        "'Response.\n'"+ 
        ".concat('Headers : ').concat(headers.toString()).concat('\n')"+ 
        ".concat('Payload : ').concat(payload.toString())" 
       ) 
      .get(); 
} 

    @Bean 
public IntegrationFlow errorFlow(){ 
    return IntegrationFlows.from(errorChannel())                 
          .log(Level.DEBUG,"trace.http", "'Ocurred an error in httpResponse :'.concat(payload.message)") 
          .transform("payload.failedMessage")        
          .handle((p,h) -> 
             MessageBuilder.withPayload(new GenericMessage<>(p,h))) 
          .transform(Transformers.toJson()) 
          .enrichHeaders(c -> c.headerExpression(FileHeaders.FILENAME, "'emailErrors-'.concat(headers.getTimestamp()).concat('.json')")) 
          .handle(fileOutboundAdapter())        
          .get(); 
} 

日誌打印:

postSend上信道 'errorChannel',消息(發送=真):的ErrorMessage [有效載荷= org.springframework.messaging.MessagingException:調度未能交付消息;嵌套異常是org.springframework.messaging.core.DestinationResolutionException:沒有可用的輸出信道或replyChannel頭,標頭= {ID = 826074c0-d1c6-4ecf-44f0-6da697b29f9c,時間戳= 1484650523378}]

更新後加裏·拉塞爾sugestion

...

@Bean 
public IntegrationFlow send(){ 
    return IntegrationFlows.from("service.input") 
      .log(Level.DEBUG, "trace.http", 
        "'Request.\n'"+ 
        ".concat('Headers : ').concat(headers.toString()).concat('\n')"+ 
        ".concat('Payload : ').concat(payload.toString())" 
       )        
      .channel(MessageChannels.queue()) 
      .handle(this.httpOutboundAdapter() 
      .transform(Transformers.toJson()) 
      .log(Level.DEBUG, "trace.http", 
        "'Response.\n'"+ 
        ".concat('Headers : ').concat(headers.toString()).concat('\n')"+ 
        ".concat('Payload : ').concat(payload.toString())" 
       ) 
      .channel("nullChanel") 
      .get(); 
} 

日誌

2017-01-17 13:58:31.929 DEBUG 19702 --- [ask-scheduler-9] osintegration.channel.DirectChannel:預發送通道'send.channel#3',消息:GenericMessage [payload = $ PAYLOAD_JSON, header = $ HEADERS] 2017-01-17 13:58:31.930 DEBUG 19702 --- [ask-scheduler-9] ositMessageTransformingHandler:org.springframework.integration.transformer.MessageTransformingHandler#0收到消息:GenericMessage [payload = $ PAYLOAD_JSON,headers = $ HEADERS] 2017-01-17 13:58:31.932 DEBUG 19702 --- [ask-scheduler-9] osintegration.channel.DirectChannel:預發送通道'send.channel#5',消息: GenericMessage [payload = $ PAYLOAD_JSON,headers = $ HEADERS] 2017-01-17 13:58:31.932 DEBUG 19702 --- [ask-scheduler-9] osintegration.handler.LoggingHandler:org.springframework.integration.handler。 LoggingHandler#1收到消息:GenericMessage GenericMessage [payload = $ PAYLOAD_JSON,headers = $ HEADE RS] 2017-01-17 13:58:31.942 DEBUG 19702 --- [ask-scheduler-9] osintegration.handler.BridgeHandler:org.springframework.integration.handler.BridgeHandler#2收到消息:GenericMessage [payload = $ PAYLOAD_JSON,headers = $ HEADERS] 2017-01-17 13:58:31.943 DEBUG 19702 --- [ask-scheduler-9] osintegration.channel.DirectChannel:preSend在通道'nullChanel',消息:GenericMessage [有效載荷= $ PAYLOAD_JSON,headers = $ HEADERS] 2017-01-17 13:58:31.944 DEBUG 19702 --- [ask-scheduler-9] osintegration.channel.DirectChannel:preSend通道'errorChannel',消息:ErrorMessage [ payload = org.springframework.messaging.MessageDeliveryException:分派器沒有訂閱者頻道'application:29891.nullChanel'。嵌套異常是org.springframework.integration.MessageDispatchingException:調度程序沒有訂閱者,標題= {id = fe0672cd-b9e4-9d43-2c5a-3d2d0a1c5493,timestamp = 1484668711944}] 2017-01-17 13:58:31.945 DEBUG 19702 - - [ask-scheduler-9] osintegration.handler.LoggingHandler:org.springframework.integration.handler.LoggingHandler#2 received message:ErrorMessage [payload = org.springframework.messaging.MessageDeliveryException:Dispatcher has no subscriber for channel'application :29891.nullChanel」;嵌套異常是org.springframework.integration.MessageDispatchingException:調度員沒有訂閱者,標題= {id = fe0672cd-b9e4-9d43-2c5a-3d2d0a1c5493,timestamp = 1484668711944}] 2017-01-17 13:58:31.949 DEBUG 19702 - - [ask-scheduler-9] ositMessageTransformingHandler:org.springframework.integration.transformer.MessageTransformingHandler#1收到消息:ErrorMessage [payload = org.springframework.messaging。MessageDeliveryException:調度具有用於信道沒有訂閱者的應用:29891.nullChanel'.;嵌套異常是org.springframework.integration.MessageDispatchingException:調度員沒有訂戶,headers = {id = fe0672cd-b9e4-9d43-2c5a-3d2d0a1c5493,timestamp = 1484668711944}] 2017-01-17 13:58:31.951 DEBUG 19702 --- [問調度-9] osintegration.channel.DirectChannel:preSend上信道 'errorFlow.channel#1',消息:GenericMessage [有效載荷= $ PAYLOAD_JSON,標頭= $ HEADERS]

我用$ PAYLOAD_JSON和$ HEADERS分別替換有效載荷和頭部以減少日誌。

回答

1

你的網關有一個void回報void send(...)這樣的框架並不期待回覆。

.log()元件是竊聽(這是第一個日誌如何讓消息流到隊列信道)。

由於您的流與一個日誌(竊聽)結束它期待的消息或應答信道的一個消費者。

我們可能作出最終.log終端,並會考慮這樣做(INT-4210),但現在你可以在最後.log之後添加.channel("nullChannel")

+0

謝謝回答。我試着像你說的那樣,但是忽略了同樣的錯誤,但是現在名稱爲「nullChannel」。
*信道 'errorChannel' preSend,消息:的ErrorMessage [有效載荷= org.springframework.messaging.MessageDeliveryExceptionDispatcher具有用於信道沒有訂閱者的應用:29891.nullChanel'.;嵌套異常是org.springframework.integration.MessageDispatchingException:調度沒有訂閱者,標題= {ID = 6f28519a-d7d3-4a84-2b76-960d340ec4c2,時間戳= 1484662227466}] * –

+0

我測試類似的,沒有任何問題流自己 - 更新問題以顯示您的新配置;也打開調試日誌的'org.springframework.integration'和展示的最後幾個日誌(在你的問題,不是在評論),而且全堆棧跟蹤。 –

+0

我更新了問題。 –

相關問題