Apache Camel Exchange / ActiveMQ – publish to multiple end points

Apache Camel Exchange is an object that Apache uses to carry context information around. You use this object to auto connect end-points dynamically leveraging camel’s connectors. If you have only one end point, this works perfectly fine.

Now you are in an environment where you are publishing to multiple end-points with different play loads. Question is can I reuse same exchange object? The simple answer is no! A more complex answer is to use camels multicast feature. However, the multicast feature works for those cases where you are publishing same payload to different end points.

In such cases where you have different payloads for different end points, and you have a single context, you need to copy/clone the exchange object for each endpoint. Add payload to a copy of the exchange and the send to the endpoint.

The reason for cloning the exchange is to create an instance for an endpoint only so that each endpoint has its own copy of the exchange. This avoid any unintended consequences due to concurrent processing in camel.