10.2. 内容过滤器
概述
内容过滤器 模式描述了在将消息传送到预期收件人前需要从消息过滤额外内容的情况。例如,您可能使用内容过滤器从消息中剥离机密信息。
图 10.2. 内容过滤器模式
过滤消息的常用方法是使用 DSL 中的表达式,以一种受支持的脚本语言(例如: XSLT、XQuery 或 JoSQL)编写。
实施内容过滤器
内容过滤器基本上是消息处理技术以特定用途的应用。要实施内容过滤器,您可以使用以下任何消息处理技术:
- message translator 时间为 第 5.6 节 “message Translator”。
- 处理器 abrt-abrt 请参阅 第 35 章 实现处理器。
- Bean 集成.
XML 配置示例
以下示例演示了如何在 XML 中配置相同的路由:
<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="activemq:My.Queue"/> <to uri="xslt:classpath:com/acme/content_filter.xsl"/> <to uri="activemq:Another.Queue"/> </route> </camelContext>
使用 XPath 过滤器
您还可以使用 XPath 过滤出您感兴趣的消息的一部分:
<route> <from uri="activemq:Input"/> <setBody><xpath resultType="org.w3c.dom.Document">//foo:bar</xpath></setBody> <to uri="activemq:Output"/> </route>