In some scenarios, we may have a need to avoid getting any unwanted or unnecessary messages. To solve these issues, we can use a Message Filter (a special type of Message Router) to eliminate these types of messages.
In the following example, we see the implementation of a Message Filter pattern to evaluate a conditional predicate using a boolean true or false. It will only allow the true condition to pass through the filter, whereas all of the false conditions will be ignored.
Java DSL Example
In this example, we want to read the header of the message, if it is a Test message, then it will be ignored. If it isn’t then it will be forwarded to the order queue.
from("jms:queue:inbox")
.filter(header("Test").isNotEqualTo("true"))
.to("jms:queue:order");