简体   繁体   English

从服务异常中检索Spring Integration中的消息

[英]Retrieving message in Spring Integration from Service Exception

I am developing a Restful API using Spring Integration and I am stuck retrieving messages when an exception raises from one of my services. 我正在使用Spring Integration开发一个Restful API,当我的一项服务引发异常时,我一直坚持检索消息。

This is my app-context: 这是我的应用程序上下文:

<int-http:inbound-gateway   id="v1.getEvent.inbound.gateway"
                            path="/ptgapi/{apiVersion}/clients/{clientId}/events/{eventId}"
                            supported-methods="GET"
                            request-channel="v1.getEvent.channel.input"
                            reply-channel="v1.getEvent.channel.output"
                            error-channel="v1.getEvent.channel.error"
                            convert-exceptions="true"
                            mapped-request-headers="HTTP_REQUEST_HEADERS,X-ptg-client-token,X-ptg-user-id,X-ptg-user-token,X-ptg-channel"
                            request-timeout="50000"
                            reply-timeout="50000">

    <int-http:header name="apiVersion" expression="#pathVariables.apiVersion"/>
    <int-http:header name="clientId" expression="#pathVariables.clientId"/>
    <int-http:header name="eventId" expression="#pathVariables.eventId"/>

</int-http:inbound-gateway>

<int:chain input-channel="v1.getEvent.channel.input" output-channel="v1.getEvent.channel.output" send-timeout="50000">

    <int:header-enricher>
        <int:error-channel ref="v1.getEvent.channel.error" />
    </int:header-enricher>

    <int:service-activator ref="v1.validation.service" method="validateRequest"/>
    <int:service-activator ref="v1.getEvent.service" method="getEvent"/>    
    <int:object-to-json-transformer/>

</int:chain>

<int:chain input-channel="v1.getEvent.channel.error" output-channel="v1.getEvent.channel.output">
    <int:transformer ref="errorUnwrapper" method="manageError" />
</int:chain>

My errorUnwrapper transformer is: 我的errorUnwrapper变压器是:

@MessageEndpoint public class ErrorUnwrapper { @MessageEndpoint公共类ErrorUnwrapper {

@Transformer
public Message<?> manageError(Message<?> errorMessage) {

    Message<?> failedMessage = ((MessagingException) errorMessage.getPayload())
                                .getFailedMessage();

    Message<?> messageOut = MessageBuilder
                                .withPayload("")
                                .copyHeadersIfAbsent(failedMessage.getHeaders())
                                .setHeaderIfAbsent(HttpHeaders.STATUS_CODE, HttpStatus.ALREADY_REPORTED)
                                .build();
    return failedMessage;
}

} }

The idea is assign the status error code in the transformer to inform the user but the info never reaches the client although I can confirm the return statements is reached in debug mode... 想法是在转换器中分配状态错误代码以通知用户,但信息永远不会到达客户端,尽管我可以确认在调试模式下已到达返回语句...

What's could be the problem here? 这可能是什么问题?

Thanks! 谢谢!

The problem is you are replying to the defunct replyChannel header from the failedMessage ; 问题是您正在从failedMessage答复已失效的ReplyChannel标头; the gateway is waiting for a reply on the replyChannel header in the errorMessage. 网关正在等待对errorMessage中的ReplyChannel标头的答复。

You can simply use the errorMessage or, if you need other headers from the failedMessage, use copyHeaders(errorMessage.getHeaders()).copyHeadersIfAbsent(failedMessge.getHeaders()) . 您可以简单地使用errorMessage,或者,如果需要来自failMessage的其他标头,请使用copyHeaders(errorMessage.getHeaders()).copyHeadersIfAbsent(failedMessge.getHeaders())

This will retain the correct replyChannel. 这将保留正确的replyChannel。

In 3.0 (currently at milestone 2), we have added enhanced diagnostics to report this fairly common mistake (where a reply is sent to a defunct reply channel). 在3.0(当前处于里程碑2)中,我们添加了增强的诊断功能来报告此相当常见的错误(将回复发送到已失效的回复频道)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Integration(MQTT):检索已发布的消息 - Spring Integration(MQTT): Retrieving published message Spring 集成:如何通过服务激活器作为并行服务使多线程从可轮询通道轮询消息 - Spring integration: how to make multi thread to poll message from a pollable channel through service activator as a paraller service Spring Integration DSL,从消息通道轮询 - Spring Integration DSL, poll from message channel 来自Transformer的Spring Integration路由消息 - Spring Integration route message from Transformer 通过Spring集成从队列中消费消息 - consuming message from a queue through spring integration Spring Integration-如何处理LoggingHandler的异常 - Spring Integration - How to handle exception from LoggingHandler 验证器异常 Spring 集成:在验证器中返回错误消息 - Validator Exception Spring Integration: returning an error message in validator Web 服务将 Soap 消息放入队列中,并带有 Spring 集成和 Jms - Web service putting Soap message in queue with Spring Integration and Jms 如何在Spring Integration中将服务分配给message-driven-adapter? - How to assign a service to message-driven-adapter in Spring Integration? Spring 引导(REST 服务)集成测试因 null 指针异常而失败 - Spring Boot (REST Service) Integration tests fail with a null pointer exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM