如何将原始消息有效负载发送到jms错误队列

时间:2014-08-21 01:47:46

标签: spring-integration

在下面的示例Spring Integration消息流中,我需要能够重新处理原始消息。我有一个例外的区域是变压器或最后调用Web服务。所以我到目前为止看到的是,一旦通过变换器或服务更改了有效负载,我就无法回滚到放置在jms队列上的原始消息。是否有一个功能允许我在发生异常时将原始消息发送到不同的jms队列?

<int-jms:message-driven-channel-adapter
        id="Jms" 
        connection-factory="connectionFactory"      
        destination="queue" 
        channel="XMLChannel"
        error-channel="errorChannel"

        />  

    <int:channel id="XMLChannel"/>  

    <int:chain input-channel="XMLChannel" output-channel="ObjectChannel">
        <int-xml:unmarshalling-transformer id="defaultUnmarshaller" unmarshaller="xmlMarshaller"  />
    </int:chain>    

    <int:channel id="ObjectChannel"/>

    <int:chain id="transformerChain" input-channel="ObjectChannel" output-channel="post" >

        <int:filter ref="environmentFilter" />
        <int:filter ref="emailFilter" />

        <int:transformer ref="transformer" />

        <int:object-to-json-transformer object-mapper="objectMapperFactory" />

        <int:header-enricher>
            <int:header name="content-type" value="application/json"></int:header>
        </int:header-enricher>

        <int-http:outbound-gateway 
            url="${url.${runtime.environment}}" 
            http-method="POST"
            expected-response-type="java.lang.String" 
            charset="UTF-8"
            reply-channel="post">
            <int-http:request-handler-advice-chain>
                <int:retry-advice max-attempts="3">
                    <int:exponential-back-off initial="5000"  multiplier="10.0" maximum="600000" />
                </int:retry-advice>
            </int-http:request-handler-advice-chain>
        </int-http:outbound-gateway>
    </int:chain>    

        <int:channel id="post"/>

        <int:logging-channel-adapter channel="post" level="INFO" log-full-message="true"/>

    <int:exception-type-router input-channel="addChannel" default-output-channel="errorChannel">
        <int:mapping />
    </int:exception-type-router>

    <int:channel id="errorChannel" />

    <int:chain input-channel="errorChannel">

        <int:transformer ref="errorTransformer"/>

    <!--        <int:object-to-json-transformer/>
     <int-xml:marshalling-transformer marshaller="xmlMarshaller"  /> -->
        <int-jms:outbound-channel-adapter id="dcsConsumerAppointmentError"
            connection-factory="connectionFactory" destination="dcsConsumerAppointmentErrorQueue" />

    </int:chain>




@Transformer
    public Message<?> handleFailedOrder(Message<MessageHandlingException> message) throws JAXBException, IOException {

        log.info(message.getPayload().getMessage());

        JAXBElement<CustomerRequestVO> test = (JAXBElement<CustomerRequestVO>) message.getPayload().getFailedMessage().getPayload();

        String xml = jaxbMarshalToString(test.getValue());

        Message<?> messageOut = MessageBuilder.withPayload(xml).setHeader("Exception", message.getPayload().getMessage()).build();

        return messageOut;
    }

1 个答案:

答案 0 :(得分:1)

从配置中清除什么是addChannel,但就您使用error-channel="errorChannel"而言,原始邮件(我猜它是XML)会被发送到{{ 1}} errorChannel的{​​{1}}。

如果failedMessage MessagingExceptionhandleFailedOrder <int:transformer ref="errorTransformer"/>,则errorChannel应为原始XML,而非解组message.getPayload().getFailedMessage().getPayload()

跟踪原始CustomerRequestVO的另一个技巧是在进一步处理和转换之前将其放到payload

但是,当然,您应该记住,同一个可变对象的副本将在任何地方更改,您将更改其属性一次。