LibraryToggle FramesPrintFeedback

Message Filter


A message filter, shown in Figure 50, is a processor that eliminates undesired messages based on specific criteria. Filtering is controlled by specifying a predicate in the filter: when the predicate is true, the incoming message is allowed to pass; otherwise, it is blocked. This pattern maps to the corresponding message filter pattern in Apache Camel.

Figure 50. Message Filter Pattern

Message filter pattern

Example ServiceMix EIP route

Example 20 shows how to define a message filter using the ServiceMix EIP component. Incoming messages are passed through a filter mechanism that blocks messages that lack a test:world element.

Example 20. ServiceMix EIP Message Filter

<eip:message-filter service="test:messageFilter" endpoint="endpoint">
    <eip:exchange-target service="test:trace3" />
    <eip:xpath-predicate xpath="count(/test:world) = 1" namespaceContext="#nsContext"/>

Equivalent Apache Camel XML route

Example 21 shows how to define an equivalent route using Apache Camel XML configuration.

Example 21. Apache Camel Message Filter Using XML

  <from uri="jbi:endpoint:">
   <xpath>count(/test:world) = 1</xpath>
   <to uri="jbi:service:"/>

Equivalent Apache Camel Java DSL route

Example 22 shows how to define an equivalent route using the Apache Camel Java DSL.

Example 22. Apache Camel Message Filter Using Java DSL

  filter(xpath("count(/test:world) = 1")).

Comments powered by Disqus