基于XML Payload的聚合关联策略
Aggregation Correlation Strategy based on XML Payload
问题:如何根据有效负载中的 XML 值关联聚合器的消息?我有一个调用第三方应用程序的场景,它只返回 xml 响应。基于有效负载中的 xml 值,我想关联消息以产生返回给消费者的单一响应。
使用 Header 属性的示例
@CorrelationStrategy
public Object correlate(Message message) throws JMSException {
return message.getHeaders().get("JMSXUserID");
}
解题笔记:
- 如下所述,并在 spring 文档中引用了 xml 负载支持。
http://docs.spring.io/spring-integration/reference/html/xml.html#xpath-spel-function
应用的示例配置:
<aggregator
id="agg"
input-channel="jmsInChannel"
output-channel="outputChannel"
ref="AggregatorPOJO"
method="combineResponesMessages"
correlation-strategy-expression="#xpath(payload, '/test/name')"
release-strategy="AggregatorPOJO"
release-strategy-method="isComplete"/>
这将关联以下 xml。
<test><name>test1</name></test>
您必须解析 XML;您可能能够使用简单的正则表达式 Pattern
,或者您可能必须将有效负载转换为 DOM 以应对更复杂的情况。
看看#xpath()
SpEL函数是否能帮到你,例如:
correlation-strategy-expression="#xpath(payload, '/name')"
其中 payload
是相关消息的某些 XML 表示中的有效载荷,/name
是针对该有效载荷的 XPath
。
您应该确保 spring-integratrion-xml
jar 在您的 CLASSPATH 中。
问题:如何根据有效负载中的 XML 值关联聚合器的消息?我有一个调用第三方应用程序的场景,它只返回 xml 响应。基于有效负载中的 xml 值,我想关联消息以产生返回给消费者的单一响应。
使用 Header 属性的示例
@CorrelationStrategy
public Object correlate(Message message) throws JMSException {
return message.getHeaders().get("JMSXUserID");
}
解题笔记:
- 如下所述,并在 spring 文档中引用了 xml 负载支持。
http://docs.spring.io/spring-integration/reference/html/xml.html#xpath-spel-function
应用的示例配置:
<aggregator
id="agg"
input-channel="jmsInChannel"
output-channel="outputChannel"
ref="AggregatorPOJO"
method="combineResponesMessages"
correlation-strategy-expression="#xpath(payload, '/test/name')"
release-strategy="AggregatorPOJO"
release-strategy-method="isComplete"/>
这将关联以下 xml。
<test><name>test1</name></test>
您必须解析 XML;您可能能够使用简单的正则表达式 Pattern
,或者您可能必须将有效负载转换为 DOM 以应对更复杂的情况。
看看#xpath()
SpEL函数是否能帮到你,例如:
correlation-strategy-expression="#xpath(payload, '/name')"
其中 payload
是相关消息的某些 XML 表示中的有效载荷,/name
是针对该有效载荷的 XPath
。
您应该确保 spring-integratrion-xml
jar 在您的 CLASSPATH 中。