10.2. 内容过滤器
概述
内容过滤器 模式描述了一个场景,您需要在将消息传递给其预期接收者前过滤出额外的内容。例如,您可以使用内容过滤器从消息中去除机密信息。
图 10.2. 内容过滤器模式
过滤消息的常用方法是使用 DSL 中的表达式,使用其中一个受支持的脚本语言(例如,XSLT、XQuery 或 JoSQL)。
实施内容过滤器
内容过滤器基本上是一个针对特定目的的消息处理技术应用程序。要实现内容过滤器,您可以使用以下任何消息处理技术:
- Message translator criu-categoriessee 第 5.6 节 “message Translator”。
- 处理器 mvapich-mvapichsee 第 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>