Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.4.5. Message Router
Overview Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
A message router, shown in Figure 4.7, “Message Router Pattern”, is a type of filter that consumes messages from a single consumer endpoint and redirects them to the appropriate target endpoint, based on a particular decision criterion. A message router is concerned only with redirecting messages; it does not modify the message content.
Figure 4.7. Message Router Pattern
A message router can easily be implemented in Apache Camel using the
choice()
processor, where each of the alternative target endpoints can be selected using a when()
subclause (for details of the choice processor, see Section 1.5, “Processors”).
Java DSL example Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The following Java DSL example shows how to route messages to three alternative destinations (either
seda:a
, seda:b
, or seda:c
) depending on the contents of the foo
header:
from("seda:a").choice() .when(header("foo").isEqualTo("bar")).to("seda:b") .when(header("foo").isEqualTo("cheese")).to("seda:c") .otherwise().to("seda:d");
from("seda:a").choice()
.when(header("foo").isEqualTo("bar")).to("seda:b")
.when(header("foo").isEqualTo("cheese")).to("seda:c")
.otherwise().to("seda:d");
XML configuration example Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The following example shows how to configure the same route in XML:
Choice without otherwise Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
If you use
choice()
without an otherwise()
clause, any unmatched exchanges are dropped by default.