`
honno
  • 浏览: 56461 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

OSGI在ServiceMix4.0中的应用

阅读更多

感受OSGI在ServiceMix4.0中的应用
                                        
ServiceMix4介绍
ServiceMix4是一个令人期待的ServiceMix新版本,它不仅支持JBI规范,更重要的是支持OSGI。与ServiceMix3.x相比,对OSGI的支持是它最大的特色。它包括Kernel和NMR两个项目。Kernel是基于OSGI实现框架Flex实现的,它是ServiceMix4的基石;NMR构建于Kernel之上,它是JBI规范的具体实现。

ServiceMix4架构图

 


关于ServiceMix4可以参看这里

关于Kernel可以参看这里


关于NMR可以参看这里


由于ServiceMix4同时支持OSGI和JBI,所以它支持OSGI和JBI这2种部署。部署在ServiceMix3.x上的组件绝大多数可以直接部署在ServiceMix4中。

关于ServiceMix3.x到ServiceMix4的迁移,可以参看这里


下面来看看基于OSGI部署的组件如何部署在ServiceMix4中。


初试ServiceMix4


准备工作

下载ServiceMix4
下载地址:http://servicemix.apache.org/SMX4/download.html

安装ServiceMix4
直接将下载后的文件解压即可。

启动ServiceMix4
直接双击/bin文件夹中的servicemix.bat,片刻之后,就可以启动ServiceMix4。
启动后的界面如下:



基于OSGI的最简单实例


该实例实现了将一个文件夹中的xml文件拷贝到另外一个文件夹中。
代码片段如下:

......
<bean class="org.apache.servicemix.common.osgi.EndpointExporter"/>

<file:poller service="honnom:pollFile" endpoint="pollEndpoint"
             file="honnom/inBox/" targetService="honnom:sendFile" >
</file:poller>

<file:sender service="honnom:sendFile" endpoint="sendEndpoint"
             directory="honnom/outBox/">
</file:sender>
.....

代码介绍
<bean class="org.apache.servicemix.common.osgi.EndpointExporter"/>
使用该bean完成poller和sender的OSGI注册。

<file:poller service="honnom:pollFile" endpoint="pollEndpoint"
             file="honnom/inBox/" targetService="honnom:sendFile" >
</file:poller>
定义一个poller,周期性地从文件夹honnom/inBox中读取xml格式的文件。
<file:sender service="honnom:sendFile" endpoint="sendEndpoint"
             directory="honnom/outBox/">
</file:sender>
定义一个sender,将接收到的文件存放在文件夹honnom/outBox中。


部署

直接将file-osgi.xml拷贝到ServiceMix4的安装目录的deploy下。

运行
ServiceMix4部署完file-osgi.xml后,会在/bin文件夹下生成两个子目录:
honnom/inBox和honnom/outBox。拷贝一个xml格式的文件到inBox中,几秒钟后该文件会被转移到outBox中。

总结
可以看出ServiceMix4的部署更加简单,可以直接通过OSGI部署xml文件,而不需要将xml打包成sa(.zap文件)。当然也可以将xml打包成sa,以JBI组件的方式进行部署。

 

  • 大小: 16.5 KB
  • 大小: 17.5 KB
  • 大小: 25.3 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics