Spring集成错误安装完成有效载荷

问题描述 投票:0回答:1

我有一个监听到JMS。当我阅读邮件,然后我转换到我的自定义对象

public IntegrationFlow queueProcessorFlow() {
        return IntegrationFlows.from(Jms.inboundAdapter(jmsTemplate)

                        .destination("test_queue"),
                c -> c.poller(Pollers.fixedDelay(5000L)
                        .maxMessagesPerPoll(1)))

                //convert json to our custom object
                .transform(new JsonToQueueEventConverterTransformer(springBeanFactory))

                .transform(new CustomTransformer(springBeanFactory))


                .handle(o -> {


                }).get();
    }

变压器

public class CustomerTransformer implements GenericTransformer<CustomPojo, CustomPojo> {


    private final QueueDataProcessorSpringBeanFactory factory;


    @Override
    public CustomPojo transform(CustomPojo CustomPojo) {
        try {

           //do something e.g. service call
           throw new Exception("This failed mate !! SOS");
        } catch (Exception e) {            

        //ISSUE here 
        //e contains the original payload in the stack trace 
            throw new RuntimeException(e);
        }
        return CustomPojo;

    }

现在,当我把我的自定义异常堆栈跟踪中包含的一切。它甚至还包含了有效载荷。我不是在例外的情况下,感兴趣的有效载荷。

如何更新不包括有效载荷?

** **更新

改变,因为每个答案后,我仍然看到问题

org.springframework.integration.transformer.MessageTransformationException: Failed to transform Message; nested exception is org.springframework.messaging.MessageHandlingException: nested exception is org.springframework.integration.transformer.MessageTransformationException: Error initiliazing the :; nested exception is CustomException Error lab lab lab  , failedMessage=GenericMessage [payload=

我的错误处理程序

 @Bean
    public IntegrationFlow errorHandlingFlow() {
        return IntegrationFlows.from("errorChannel")
                .handle(message -> {
                    try {

                        ErrorMessage e = (ErrorMessage) message;
                        if (e.getPayload() instanceof MessageTransformationException) {
                            String stackTrace = ExceptionUtils.getStackTrace(e.getPayload());
                            LOG.info("Exception trace {} ", stackTrace);
java spring-integration spring-integration-dsl
1个回答
1
投票

不知道是什么的经营宗旨,以失去在堆栈跟踪payload,但你可以做到这一点扔MessageTransformationException而不是RuntimeException的。

为了避免堆栈跟踪信息与有效载荷提到,你需要使用这些构造函数:

public MessageTransformationException(String description, Throwable cause) {
    super(description, cause);
}

public MessageTransformationException(String description) {
    super(description);
}

取而代之的基础上,Message<?>那些。

这样的包装MessageTransformingHandler会做一个适当的逻辑:

protected Object handleRequestMessage(Message<?> message) {
    try {
        return this.transformer.transform(message);
    }
    catch (Exception e) {
        if (e instanceof MessageTransformationException) {
            throw (MessageTransformationException) e;
        }
        throw new MessageTransformationException(message, "Failed to transform Message", e);
    }
}

UPDATE

原来,MessageTransformationException不是因为AbstractMessageHandler检查的MessageHandlingExceptionIntegrationUtils.wrapInHandlingExceptionIfNecessary()包装不够。因此,我建议抛出从您的代码,而不是MessageHandlingException。而使用此构造与null的消息ARG:

MessageHandlingException(Message<?> failedMessage, Throwable cause)
© www.soinside.com 2019 - 2024. All rights reserved.