Camel in OSGi Container: Apply InterceptStrategy to all camel contexts

隐身守侯 提交于 2019-12-03 22:18:48

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!