Datapower中退避队列无负载及动态注入退避计数头问题咨询
问题解决方案
1. 修正代码语法错误
你现有代码的target属性存在引号书写错误,target="{$BackoutQ"}应改为target="{$BackoutQ}",否则会导致队列地址解析异常。
2. 动态注入退避计数
需要从原消息的MQMD中读取BackoutCount值,递增后写入新的MQMD节点:
- 用
dp:request-header('MQMD/BackoutCount')获取原退避计数,首次退避时默认值设为0 - 对数值递增后,通过
<mq:BackoutCount>节点覆盖原MQMD中的对应字段
3. 传递消息负载
在dp:url-open标签内添加原消息负载的拷贝,确保退避队列能收到完整的消息内容。
完整修正后的XSLT代码
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" xmlns:mq="http://www.ibm.com/xmlns/prod/websphere/mq/7.0.0/mqmd" extension-element-prefixes="dp"> <xsl:variable name="originalBackoutCount" select="dp:request-header('MQMD/BackoutCount')"/> <!-- 处理首次退避场景,默认退避计数为0 --> <xsl:variable name="newBackoutCount" select="number($originalBackoutCount) + 1"/> <xsl:template match="/"> <dp:url-open target="{$BackoutQ}" http-headers="$headers" response="responsecode-ignore" timeout="10" data-type="xml"> <!-- 拷贝原MQMD并更新退避计数 --> <mq:MQMD> <xsl:copy-of select="dp:request-header('MQMD/*') except dp:request-header('MQMD/BackoutCount')"/> <mq:BackoutCount><xsl:value-of select="$newBackoutCount"/></mq:BackoutCount> </mq:MQMD> <!-- 传递原消息负载 --> <xsl:copy-of select="/"/> </dp:url-open> </xsl:template> </xsl:stylesheet>
关键说明
- 命名空间引入:必须添加
mq命名空间,否则MQMD节点无法被Datapower正确识别 - 退避计数更新:通过
except排除原MQMD中的旧退避计数字段,避免节点重复 - 负载传递:
<xsl:copy-of select="/"/>会将整个原消息内容拷贝到退避请求中,确保队列收到完整负载 - 变量解析:修正后的
target属性能正确解析$BackoutQ变量对应的退避队列地址
验证要点
- 确认
$BackoutQ变量已配置为正确的MQ队列地址(格式示例:mq://queueManager/backoutQueue) - 检查Datapower的MQ前端处理程序是否拥有退避队列的写入权限
- 可通过
dp:trace()输出$newBackoutCount和负载内容,验证数据传递正确性
内容的提问来源于stack exchange,提问作者Daisy
相关产品推荐
相关产品推荐

