【问题标题】:Expose an OSGi Service as Camel Endpoint将 OSGi 服务公开为 Camel 端点
【发布时间】:2016-05-04 07:01:28
【问题描述】:

我什至不知道我是否以正确的方式提出问题;-)

我基本上想要实现的是这样的:

<route >
    <from uri="osgi:serviceName"/>
    <!-- do some processing ->
    <to uri="activemq:queue:inbox"/>
</route>

所以我希望有一个 OSGi 服务作为我路线的起点。该服务可以被其他一些捆绑包引用,并馈送输入数据,稍后将由路由处理。

我该怎么做?

【问题讨论】:

    标签: apache-camel osgi blueprint-osgi


    【解决方案1】:

    只需在camel 之外创建一个OSGi 服务和一个以direct:anyname 开头的路由。然后,您可以将 ProducerTemplate 注入您的服务并从那里调用路由。

    【讨论】:

    • 您能否更详细地解释一下“将 ProducerTemplate 注入您的服务”?或者你有一个例子吗?干杯!
    • 我认为最简单的方法是注入 CamelContext 并执行 ProducerTemplate producer = contrext.createProducerTemplate();
    【解决方案2】:

    如果你有非常简单的方法签名,或者你想要传递的参数的 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>
    

    【讨论】:

      【解决方案3】:

      要在 Camel 路由中使用“osgi”作为 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。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-21
        • 2011-03-03
        • 2019-03-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多