[英]Expose an OSGi Service as Camel Endpoint
我什至不知道我是否以正确的方式提出了这个问题;-)
我基本上想要实现的是这样的:
<route >
<from uri="osgi:serviceName"/>
<!-- do some processing ->
<to uri="activemq:queue:inbox"/>
</route>
因此,我想将OSGi服务作为我的路线的起点。 该服务可以被其他一些捆绑包引用,并提供输入数据,稍后将由Route处理。
我该怎么做?
只需在骆驼之外创建OSGi服务,并创建一个以direct:anyname开头的路由。 然后,您可以将ProducerTemplate注入到服务中,从那里调用路由。
如果您具有非常简单的方法签名,或者要传递的参数使用typeConverter ,则可以使用CamelProxy将服务链接到简单XML配置文件中的路由。
为了扩展文档的示例,您将具有以下内容:
<osgi:service id="service" ref="myProxySender" (4)
interface="org.apache.camel.spring.config.MyProxySender" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<!-- create a proxy that will route to the direct:start endpoint when invoked -->
<proxy id="myProxySender"
serviceInterface="org.apache.camel.spring.config.MyProxySender"
serviceUrl="direct:start"/>
<!-- this is the route that our proxy will routed when invoked
and the output from this route is returned as reply on the proxy -->
<route>
<from uri="direct:start"/>
<transform>
<simple>Bye ${body}</simple>
</transform>
</route>
</camelContext>
要将“ osgi”用作Camel路由中的URI方案,您需要创建一个自定义的Camel组件来处理调用相关的OSGi命令。 有关更多信息,请参见http://camel.apache.org/creating-a-new-camel-component.html
一种更简单的选择是编写自定义OSGi命令,该命令使用ProducerTemplate将消息发送到Camel路由。 可以在这里找到Karaf的示例: https : //github.com/apache/karaf/tree/master/demos/command
可以通过标准的Spring配置来注入ProducerTemplate。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.