我开始使用 si-xml:xpath-router 但遇到了障碍。我是否使用了正确的路由器但实现错误?如果我使用的路由器不正确,我应该使用哪一个,即默认路由器、有效负载类型,还是简单的 SpEL 表达式?
用例:
我需要根据负载内容路由消息。该请求包含一个元素,并且我需要执行的“操作”包含在其属性中,请参阅下面的属性“命令”。
入站请求示例(来自网络服务)。
<Request>
<Records>
<Record>
<data key="name" value="Jack Bauer" />
<data key="command" value="sendSMS" />
</Record>
</Records>
</Request>
伪代码是:
- 编码消息。
- 基于值的路由,通过 xpath-router
但我收到错误:
不支持的负载类型 [javax.xml.transform.dom.DOMResult]
<小时/>为了解决这个问题,我尝试过:
使用 ResultToDocumentTransformer 将属性“result-transformer”添加到转换器 bean。 错误=无法解析 channel 名称''
使用 StringResult 将属性“结果类型”添加到转换器。 错误 = 不支持的负载类型 [org.springframework.xml.transform.StringResult]
添加上述两项。 错误 = 无法解析 channel 名称“”
使用 true 添加属性“evaluate-as-string”。 错误 = 不支持的负载类型。
原始配置文件如下:
<gateway id="gateway" default-request-channel="requestChannel"
service-interface="foo.SomeClass" />
<beans:bean id="marshaller"
class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<beans:property name="classesToBeBound">
<beans:list>
<beans:value>com.foo.Request</beans:value>
<beans:value>com.foo.Record</beans:value>
<beans:value>com.foo.Data</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<chain input-channel="requestChannel">
<poller max-messages-per-poll="10" task-executor="executor">
<interval-trigger interval="5000" />
</poller>
<si-xml:marshalling-transformer marshaller="marshaller"/>
<si-xml:xpath-router id="instockRouter" resolution-required="true">
<si-xml:xpath-expression expression="/Request/Records/Record/data[@key='command']"/>
<si-xml:mapping value="sendSMS" channel="SMSChannel"/>
</si-xml:xpath-router>
</chain>
<task:executor id="executor" pool-size="8"/>
最佳答案
编码后您可以使用 Spring 的 "=object-to-string-transformer/>"
。
关于java - 如何使用 Spring Integration 2.0.5 根据内容路由消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6932773/