Camel in OSGi Container: Apply InterceptStrategy to all camel contexts

醉酒当歌 提交于 2019-12-21 06:53:03

问题


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 CamelContexts 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 CamelContexts 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 Processors 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:

  1. Keep A, B, and C decoupled from M (particularly during development)
  2. Ensure integrating M with A, B, and C is as easy as possible
  3. Allow M to be integrated without having to manually change A, B, or C

回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/29810796/camel-in-osgi-container-apply-interceptstrategy-to-all-camel-contexts

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