【问题标题】:Spring Integration JMS IssueSpring 集成 JMS 问题
【发布时间】:2015-11-01 00:23:04
【问题描述】:

我们正在使用 Spring Integration 从队列中消费消息,如果在处理所消费的消息时出现任何问题,则要求将消息发送到错误队列。 Flow 工作正常,但我们看到的一个问题是,当在处理消息时抛出任何异常时,消息被重定向到我们配置的错误队列,但它被附加到异常的整个堆栈跟踪中。 我们只寻找要传递到队列的原始消息。下面是我们做的配置,

<bean id="errorQ" class="com.ibm.mq.jms.MQQueue">
    <constructor-arg value="${error.queue}" />
</bean>
<bean id="inQ" class="com.ibm.mq.jms.MQQueue">
    <constructor-arg value="${inbound.queue}" />
</bean>

<int:channel id="error" />
<int:channel id="inbound" />

<int-jms:message-driven-channel-adapter
    id="jmsIn" channel="inbound" container="messageListenerContainer"
    acknowledge="transacted"></int-jms:message-driven-channel-adapter>

<int-jms:outbound-channel-adapter id="jmsError"
channel="error" connection-factory="mqConnectionFactory"
destination="errorQ" delivery-persistent="true"></int-jms:outbound-channel-adapter>


<int:service-activator id="service"
input-channel="inbound" ref="messageListener" method="someMethodInListerner">
    <int:request-handler-advice-chain>
        <ref bean="retryWithBackoffAdviceSession" />
    </int:request-handler-advice-chain>

<bean id="retryWithBackoffAdviceSession"
    class="org.springframework.integration.handler.advice.RequestHandlerRetryAdvice">
    <property name="retryTemplate">
        <bean class="org.springframework.retry.support.RetryTemplate">
            <property name="backOffPolicy">
                <bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
                    <property name="initialInterval" value="${initialInterval}" />
                    <property name="multiplier" value="${multiplier}" />
                    <property name="maxInterval" value="${maxInterval}" />
                </bean>
            </property>
            <property name="retryPolicy">
                <bean class="org.springframework.retry.policy.SimpleRetryPolicy">
                    <property name="maxAttempts" value="${redelivery}" />
                </bean>
            </property>
        </bean>
    </property>
    <property name="recoveryCallback">
        <bean
            class="org.springframework.integration.handler.advice.ErrorMessageSendingRecoverer">
            <constructor-arg ref="error" />
        </bean>
    </property>
</bean>

【问题讨论】:

    标签: jms spring-integration spring-retry


    【解决方案1】:

    发送到error 的消息是ErrorMessage,有效负载为MessagingException

    MessagingException 有两个属性 causefailedMessage

    因此,如果您想将原始失败消息发送到errorQ,则需要在错误流中添加一个转换器...

    <int:transformer ... expression="payload.failedMessage" />
    

    编辑

    <int:chain input-channel="error">
        <int:transformer expression="payload.failedMessage" />
        <int-jms:outbound-channel-adapter ... />
    </int:chain>
    

    EDIT2

    通常,在使用这些技术时,传达失败的原因很有用。您可以将异常的消息添加为标题...

    <int:chain input-channel="error">
        <int:header-enricher>
            <int:header name="failureReason" expression="payload.cause.message" />
        </int:header-enricher>
        <int:transformer expression="payload.failedMessage" />
        <int-jms:outbound-channel-adapter ... />
    </int:chain>
    

    【讨论】:

    • 嗨,Gary,现在在上面也添加了输入通道代码,因此它正在流中处理。我确实理解您关于添加转换器以仅将原始有效负载发送到错误队列的评论,但我需要将其放在流中的哪个位置?
    • 我认为添加一个通过有效负载的转换器应该可以工作吗?
    • 带有expression="payload" 的转换器什么都不做 - 请参阅我的编辑。
    • 对不起 - 我错过了你使用重试恢复,但转换器是一样的,因为恢复器也创建了一个 ErrorMessage
    • 捕获失败的原因并将其作为 errorQ 中的标头传达可能很有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    • 2013-01-06
    • 1970-01-01
    • 2013-02-04
    • 1970-01-01
    • 2021-11-06
    • 2012-11-09
    相关资源
    最近更新 更多