【问题标题】:set endpoint of an OSGI Blueprint file in ServiceMix在 ServiceMix 中设置 OSGI 蓝图文件的端点
【发布时间】:2015-01-22 16:42:52
【问题描述】:

我知道我可以使用蓝图语法在独立的 xml 文件中定义 Camel 路由。如果我将其中一个文件移动到 ServiceMix 的“deploy”文件夹中,它会自动成为一个 OSGI 包。我的问题是,我可以为这个新捆绑包设置一个端点,可以从外部访问吗?

我想做这样的事情:

blue_route1.xml

<blueprint>
  <camelContext>
    <route>
      <from uri="http:my_servicemix:8181/blue_route1_endpoint" />
      <to uri="jetty:http://server1" />
    </route>
  </camelContext>
</blueprint>

blue_route1 部署后成为 OSGI 包,但我应该在哪里定义 "blue_route1_endpoint" ?可行吗?

[更新]

夏天,我希望外部 WS 能够向 blue_route1_endpoint 发送消息,其中 blue_route1 捆绑包将根据 Camel 路由重定向消息,而无需创建要在 ServiceMix 中部署的新 WS“Blue_route1

                                   ______________________
                                   |     ____________   |
external-->(blue_route1_endpoint)==|==-->|blue_route1|--|-->(http://server1)
  WS                               |     |___________|  |
                                   |____________________|
                                          ServiceMix

【问题讨论】:

  • 从外部访问是什么意思,是指使用HTTP吗?然后代替 http 使用 jetty 或 servlet 组件。
  • 我希望外部 WebService 能够向其发送 SOAP 消息。是否有可能,或者我需要创建一个“假”WS 来部署在 ServiceMix 中,以便使用骆驼路由重定向消息?我更新了问题,试图更清楚

标签: apache-camel blueprint-osgi apache-servicemix


【解决方案1】:

找到了!我不明白这很容易。要让 ServiceMix 在端口上侦听,我只需使用 Camel-jetty 组件指定端点。 所以,为了回答我的问题,我是这样解决的:

在ServiceMix中安装camel-jetty组件

features:install camel-jetty 

在 blue_route1.xml 文件中用蓝图编写骆驼路线

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
    http://www.osgi.org/xmlns/blueprint/v1.0.0
    http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
        <route>
            <from uri:="jetty:http:my_servicemix:8181/blue_route1_endpoint">
            <to uri="http://localhost:8080/user/services/user?bridgeEndpoint=true&amp;throwExceptionOnFailure=false"/>
        </route>
        <route>
            <from uri="jetty:http://0.0.0.0:6969/sp_role?matchOnUriPrefix=true"/>
            <setHeader headerName="Content-Type">
                <groovy>"text/xml; charset=utf-8"</groovy>
            </setHeader>
            <to uri="http://server1"/>
        </route>        
    </camelContext>
</blueprint>

我使用了一个随机端口 8181 来监听...但我可以选择每个数字,ServiceMix 将自动启动一个码头组件,在该端口/端点上监听和消费。

【讨论】:

    【解决方案2】:

    对于 SOAP 消息,您需要 CXF Component 和 Web 服务的 wsdl 文件。您可以像这样在 camelContext 之外配置端点:

    <cxf:cxfEndpoint id="yourId" address="/your/address/to/endpoint"
        serviceClass="your.java.ServiceClass"
        wsdlURL="path/to/your/wsdl/file.wsdl" />
    

    在你的路线中使用这样的标签:

    <from uri="cxf:bean:yourId"/>
    

    你需要在你的蓝图中添加命名空间和 schemaLocation 来使用 cxf 命名空间,使用这个:

    <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
    xsi:schemaLocation="
             http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
             http://camel.apache.org/schema/blueprint/cxf http://camel.apache.org/schema/blueprint/cxf/camel-cxf.xsd
             http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-21
      • 1970-01-01
      • 2013-07-09
      • 2016-08-12
      • 1970-01-01
      • 1970-01-01
      • 2016-01-25
      • 2012-11-22
      相关资源
      最近更新 更多