I have several bundles (A, B, and C) deployed to an OSGi container, each containing a CamelContext
and some routes. I have another bundle (M) with a CamelContext
with a route (for collecting monitoring data) and a InterceptStrategy
bean. I would like the InterceptStrategy
bean from M to automatically apply to all of the other CamelContext
s in the container (i.e., those in A, B, and C), without having to modify the other bundles.
Ultimately, the goal is to wiretap data from each CamelContext
into the route in M, without having to make any changes to A, B, or C to explicitly route the Exchange
. Is this approach or a similar approach doable?
All of the CamelContext
s are configured using Spring XML.
Update: Additional Context
Bundles A, B, and C contain the core product responsible for processing data. Bundle M contains an optional monitoring tool, designed to measure certain parameters of the data flowing through A, B, and C. Currently, adding on the optional tool requires changing the routes in A, B, and C to add additional Processor
s to enrich the Exchange
with the monitoring data and to read the monitoring data prior to <to />
endpoints.
The goal is to be able to drop in Bundle M into a already verified-as-working system with A, B, and C; and have it automatically apply to the existing routes without having to modify the configuration for the existing-and-working bundles. It is acceptable to make modifications to A, B, and C to support this, as long as the changes do not cause A, B, and C to rely on M to run (i.e., ABC must still run without M).
If there is a better means to do this than using interceptors, I am open to that. The primary goals are:
I dont think this is possible using InterceptorStrategy
since that expects it is running in the same camel context. The only ways I am aware of working across multiple contexts is using the VM endpoint (which is obviously limited to the same JVM), however in this case you would probably be better utilising JMS, JMX or something similar.
JMS
Create an InterceptorStrategy
for each camel context in A, B & C
that publishes your messages to M
intercept().bean(transformForMonitoring).to("jms:queue:monitoring");
from("whatever:endpoint")
.process(myProcessor)
.to("target:endpoint");
You could also use the vm
component on the intercept()
if you dont want the overhead of JMS, however this limits your monitoring component to a single JVM.
JMX
This is a bit more complicated, but the basic idea is to tell the camel context to publish MBeans for A, B & C
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<jmxAgent id="agent" mbeanObjectDomainName="your.domain.name"/>
...
</camelContext>
and then have M
connect to the JVM MBean Server and utilise something like NotificationListener to react to the Exchanges.
One of the possibility is define a custom Tracer in Bundle 'M' and export it as osgi service.
In bundle A,B,C define osgi-reference to exported Tracer bean
Use camel JMX to enable trace.
This will result changes in bundle A,B,C but it will be minimal and it will also give ability to integrate and configure tracing (intercepting)
I have not tried this myself, but hth
Either use Spring-DM, or better transform all your spring xml based routes to blueprint ones. This is the best supported way of using XML based Routes in Karaf/Osgi.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With