简体   繁体   English

OSGi容器中的Camel:将InterceptStrategy应用于所有驼峰上下文

[英]Camel in OSGi Container: Apply InterceptStrategy to all camel contexts

I have several bundles (A, B, and C) deployed to an OSGi container, each containing a CamelContext and some routes. 我有几个软件包(A,B和C)部署到OSGi容器,每个包含一个CamelContext和一些路由。 I have another bundle (M) with a CamelContext with a route (for collecting monitoring data) and a InterceptStrategy bean. 我有另一个包(M)与CamelContext ,路由(用于收集监控数据)和InterceptStrategy bean。 I would like the InterceptStrategy bean from M to automatically apply to all of the other CamelContext s in the container (ie, those in A, B, and C), without having to modify the other bundles. 我希望M中的InterceptStrategy bean自动应用于容器中的所有其他CamelContext (即A,B和C中的那些),而不必修改其他bundle。

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 . 最终,目标是将每个CamelContext数据窃听到M中的路由,而无需对A,B或C进行任何更改以显式路由Exchange Is this approach or a similar approach doable? 这种方法或类似的方法是否可行?

All of the CamelContext s are configured using Spring XML. 所有CamelContext都是使用Spring XML配置的。


Update: Additional Context 更新:附加上下文

Bundles A, B, and C contain the core product responsible for processing data. 捆绑包A,B和C包含负责处理数据的核心产品。 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. Bundle M包含一个可选的监控工具,用于测量流经A,B和C的数据的某些参数。目前,添加可选工具需要更改A,B和C中的路由以添加额外的Processor以丰富Exchange与监控数据并在<to />端点之前读取监控数据。

The goal is to be able to drop in Bundle M into a already verified-as-working system with A, B, and C; 目标是能够将Bundle M放入已经过验证的A,B和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 (ie, ABC must still run without M). 只要更改不会导致A,B和C依赖于M来运行(即,ABC必须仍然在没有M的情况下运行),对A,B和C进行修改以支持这一点可以接受的。

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) 保持A,B和C与M分离(特别是在开发期间)
  2. Ensure integrating M with A, B, and C is as easy as possible 确保将M与A,B和C集成在一起尽可能简单
  3. Allow M to be integrated without having to manually change A, B, or C 允许集成M而无需手动更改A,B或C.

I dont think this is possible using InterceptorStrategy since that expects it is running in the same camel context. 我不认为使用InterceptorStrategy是可能的,因为它期望它在相同的camel上下文中运行。 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. 我知道在多个上下文中工作的唯一方法是使用VM端点(显然仅限于相同的JVM),但在这种情况下,您可能会更好地利用JMS,JMX或类似的东西。

JMS JMS

Create an InterceptorStrategy for each camel context in A, B & C that publishes your messages to M A, B & C中的每个camel上下文创建一个InterceptorStrategy用于将您的消息发布到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. 如果您不想要JMS的开销,也可以在intercept()上使用vm组件,但是这会将监视组件限制为单个JVM。

JMX JMX

This is a bit more complicated, but the basic idea is to tell the camel context to publish MBeans for A, B & C 这有点复杂,但基本的想法是告诉驼峰上下文为A, B & C发布MBean

<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. 然后让M连接到JVM MBean Server并利用NotificationListener之类的东西来对Exchange做出反应。

One of the possibility is define a custom Tracer in Bundle 'M' and export it as osgi service. 其中一种可能性是在Bundle'M'中定义一个自定义Tracer并将其导出为osgi服务。

In bundle A,B,C define osgi-reference to exported Tracer bean 在包A,B,C中,定义对导出的Tracer bean的osgi-reference

Use camel JMX to enable trace. 使用camel JMX启用跟踪。

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) 这将导致捆绑包A,B,C中的更改,但它将是最小的,并且还将提供集成和配置跟踪(拦截)的能力

I have not tried this myself, but hth 我自己没试过,但是

Either use Spring-DM, or better transform all your spring xml based routes to blueprint ones. 要么使用Spring-DM,要么更好地将所有基于spring xml的路由转换为蓝图路由。 This is the best supported way of using XML based Routes in Karaf/Osgi. 这是在Karaf / Osgi中使用基于XML的路由的最佳支持方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM