You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache Camel死信通道无法在DLQ中保留JMS_IBM_MQMD_ApplIdentityData问题

解决Apache Camel DLQ中JMS_IBM_MQMD_ApplIdentityData不显示的问题

1. 让DeadLetterChannel保留扩展JMS头

默认情况下,Camel的DeadLetterChannel不会自动传递所有非标准JMS头,得显式配置头过滤策略,允许IBM MQ相关的头通过:

定义DeadLetterChannel时,开启preserveMessageQos(true),同时配置headerFilterStrategy:

from("jms:queue:inputQueue")
    .errorHandler(deadLetterChannel("jms:queue:DLQ")
        .preserveMessageQos(true)
        .headerFilterStrategy(new DefaultHeaderFilterStrategy() {{
            // 移除对IBM MQ头的过滤,允许所有JMS_IBM_MQMD_*头传递
            getOutFilter().remove("JMS_IBM_MQMD_*");
            getInFilter().remove("JMS_IBM_MQMD_*");
        }}));

要是只想精准放行JMS_IBM_MQMD_APPLIDENTITYDATA,可以这么写:

.headerFilterStrategy().allowIn("JMS_IBM_MQMD_APPLIDENTITYDATA")
                     .allowOut("JMS_IBM_MQMD_APPLIDENTITYDATA");

2. 配置Camel JMS组件传递MQMD属性

Camel的JMS组件默认可能不会完整映射IBM MQ的原生MQMD属性,需要开启两个关键配置:

JmsComponent jmsComponent = new JmsComponent();
jmsComponent.setConnectionFactory(mqConnectionFactory);
jmsComponent.setTransferJmsMessage(true); // 传递完整的JMS消息
jmsComponent.setMapJmsMessage(false); // 禁用自动映射,保留原生MQ消息结构
context.addComponent("jms", jmsComponent);

用Spring XML配置的话:

<bean id="jmsComponent" class="org.apache.camel.component.jms.JmsComponent">
    <property name="connectionFactory" ref="mqConnectionFactory"/>
    <property name="transferJmsMessage" value="true"/>
    <property name="mapJmsMessage" value="false"/>
</bean>

3. 手动在死信处理时重置头

如果上面的配置没生效,直接在DeadLetterChannel的失败回调里手动把JMS_IBM_MQMD_APPLIDENTITYDATA头重新设置一遍:

from("jms:queue:inputQueue")
    .errorHandler(deadLetterChannel("jms:queue:DLQ")
        .onPrepareFailure((exchange, exception) -> {
            String applIdData = exchange.getIn().getHeader(JmsConstants.JMS_IBM_MQMD_APPLIDENTITYDATA, String.class);
            if (applIdData != null) {
                exchange.getIn().setHeader(JmsConstants.JMS_IBM_MQMD_APPLIDENTITYDATA, applIdData);
            }
        }));

4. 检查MQ Explorer的显示设置

别先急着改代码,有可能是MQ Explorer默认没显示这个字段:

  • 打开DLQ的消息列表,右键点击表头
  • 选"显示/隐藏列",找到ApplIdentityData勾选上,看看是不是能看到值了

验证步骤

在路由到DLQ之前加个日志,打印死信消息的所有头,确认JMS_IBM_MQMD_APPLIDENTITYDATA是否存在:

.onPrepareFailure((exchange, exception) -> {
    LOG.info("Dead letter headers: {}", exchange.getIn().getHeaders());
})

如果日志里有这个头,但MQ Explorer看不到,优先调Explorer的显示设置;如果日志里也没有,说明头在传递时丢了,再回头调整Camel的头过滤或JMS组件配置。

内容的提问来源于stack exchange,提问作者Abhishek Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 18:32:37