80.4. Functions
Camel 添加以下 XPath 函数,可用于访问交换:
| 功能 | 参数 | 类型 | 描述 |
|---|---|---|---|
| in:body | none | 对象 | 仅返回消息正文。 |
| in:header | 标头名称 | 对象 | 将返回消息正文。 |
| out:body | none | 对象 | 弃用 将返回 OUT 消息正文。 |
| out:header | 标头名称 | 对象 | 弃用 将返回 OUT 消息标头。 |
| function:properties | 属性的键 | 字符串 | 使用 a . |
| function:simple | 简单表达式 | 对象 | 来评估一个语言。 |
当返回类型是 NodeSet 时,不支持 function:properties 和 function:simple,比如在与 Split EIP 搭配使用时。
下面是一个示例,其中显示了一些正在使用的功能。
80.4.1. 功能示例 复制链接链接已复制到粘贴板!
如果要在 Spring XML 文件中配置路由,您可以使用 XPath 表达式,如下所示
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"
xmlns:foo="http://example.com/person">
<route>
<from uri="activemq:MyQueue"/>
<filter>
<xpath>/foo:person[@name='James']</xpath>
<to uri="mqseries:SomeOtherQueue"/>
</filter>
</route>
</camelContext>
</beans>
请注意,我们如何在 XPath 表达式中重复使用命名空间前缀 foo,以便更轻松地使用基于命名空间的 XPath 表达式。