Spanning Camel contexts within a single Java process

Sometimes it is convenient to share routing logic between integrations hosted in the same container, for example, as web apps or OSGi bundles. Camel provides two components that allow you to do this, synchronously through a Direct VM Component, or asynchronously through a VM Component.

This recipe will show you how a Camel route can call another route running in a different Camel context.

Getting ready

In order for messages to be passed between routes using the vm: or direct-vm: transports, the exact same instance of the camel-core library must be available within the classloader hierarchy of both applications.

In an application server such as Apache Tomcat, this means placing the camel-core.jar ...

Get Apache Camel Developer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.