簡體   English   中英

將OSGi服務公開為Camel端點

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM