HttpRequestExecutingMessageHandler:没有可用的输出通道或replyChannel标头

时间:2017-01-17 10:56:56

标签: spring-integration

我在我的应用程序中收到错误,我没有得到解决方案。 应用程序请求REST / JSON并尝试与另一个应用程序通信。有一个轮询器可以异步调用每个请求。 当一个请求总是调度错误“没有输出通道或replyChannel标头可用”并且它被重定向到errorChannel句柄。

...
@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();
}

日志打印:

  

postfnd(sent = true)在通道'errorChannel'上,消息:ErrorMessage [payload = org.springframework.messaging.MessagingException:Dispatcher无法传递消息;嵌套异常是org.springframework.messaging.core.DestinationResolutionException:没有输出通道或replyChannel标头可用,headers = {id = 826074c0-d1c6-4ecf-44f0-6da697b29f9c,timestamp = 1484650523378}]

Gary Russel消化后的更新

...

@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:preSend on channel'send.channel#3',message:GenericMessage [payload = $ PAYLOAD_JSON,headers = $ 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:preSend on channel'send.channel#5',message: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 = $ HEADERS]   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]   2017-01-17 13:58:31.943 DEBUG 19702 --- [ask-scheduler-9] o.s.integration.channel.DirectChannel:preSend on channel'nullChanel',message:GenericMessage [payload = $ PAYLOAD_JSON,headers = $ HEADERS]   2017-01-17 13:58:31.944 DEBUG 19702 --- [ask-scheduler-9] osintegration.channel.DirectChannel:preSend on channel'errorChannel',message:ErrorMessage [payload = org.springframework.messaging.MessageDeliveryException: Dispatcher没有渠道'申请的订阅者:29891.nullChanel'。嵌套异常是org.springframework.integration.MessageDispatchingException:Dispatcher没有订阅者,headers = {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收到消息:ErrorMessage [payload = org.springframework .messaging.MessageDeliveryException:Dispatcher没有通道'application:29891.nullChanel'的订阅者。嵌套异常是org.springframework.integration.MessageDispatchingException:Dispatcher没有订阅者,headers = {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 :Dispatcher没有订阅者的频道申请:29891.nullChanel'。;嵌套异常是org.springframework.integration.MessageDispatchingException: Dispatcher没有订阅者,headers = {id = fe0672cd-b9e4-9d43-2c5a-3d2d0a1c5493,timestamp = 1484668711944}]   2017-01-17 13:58:31.951 DEBUG 19702 --- [ask-scheduler-9] osintegration.channel.DirectChannel:preSend on channel'errorFlow.channel#1',message:GenericMessage [payload = $ PAYLOAD_JSON,headers = $ HEADERS]

我分别用$ PAYLOAD_JSON和$ HEADERS替换了有效负载和标头以减少日志。

1 个答案:

答案 0 :(得分:1)

您的网关有void返回void send(...),因此框架不会期待回复。

.log()元素是窃听(这是第一个日志让消息流到队列通道的方式)。

由于您的流程以日志(wireTap)结束,因此需要消息的消费者或回复频道。

我们可能会制作一个最终的.log终端,并会查看(INT-4210),但现在您可以在最后.channel("nullChannel")之后添加.log