ServiceMix中部署:OSGi Bundle和Feature
- 博客分类:
- ESB-ServiceMix
部署单个Bundle:
1. Hot Deployment
deploy
Linux下命令:cp ProjectDir/target/foo-1.0-SNAPSHOT.jar InstallDir/deploy
2. 手动部署
osgi:install
osgi:list
osgi:uninstall 181
osgi:resolve 181
osgi:start 181 182 183
osgi:stop 181 182 183
osgi:restart 181 182 183
3. 设置Bundle Start Level
Bundle的Start Level是一个正数,Bundle 的启动级别越低Bundle越优先启动。
osgi:bundel-level 60 182
osgi:start-level
部署多个Bundle:
因为许多开源的框架或工具是有多个Bundle组成的,为方便将相关的Bundle作为一个unit进行部署,
FuseESB提供了一个新的部署单元:Feature, 可以在一次部署中部署多个Bundle.
1. 创建一个Feature, 按照下面5步进行
(1) 创建一个Custom feature repository
创建目录:C:\ServiceMix-Features,在该目录下创建文件:features.xml:
<?xml version="1.0" encoding="UTF-8"?>
<features name="CustomFeatureRepository" >
</features>
name="CustomFeatureRepository"为自定义的,默认为repo-0,与Maven Repository
及OBR相比,Features Repository不提供Bundle的存储,他只提供存储Bundle引用的集合。
(2) 添加一个Feature至Custom feature repository
<?xml version="1.0" encoding="UTF-8"?>
<features>
<feature name="example-camel-bundle" version="1.0.0">
<bundle> file:C:/Projects/camel-bundle/target/camel-bundle-1.0-SNAPSHOT.jar
</bundle>
</feature>
</features>features:refreshUrl, features:list
features:list | grep example-camel-bundle
(3) 添加Local repository URL to the feature service
features:addUrl C:/ServiceMix-Features/features.xml
features:listUrl
(4) 添加依赖Feature to the feature
如果体格features依赖其他的features,可以添加features元素作为源features的子元素。当部署
拥有依赖的feature时,依赖机制将检查依赖的feature是否已经安装至容器,如果没有,依赖机制
将自动安装丢失的依赖。
<features>
<feature name="example-camel-bundle">
<bundle> file:C:/Projects/camel-bundle/target/camel-bundle-1.0-SNAPSHOT.jar
</bundle>
<feature version="4.4.1-fuse-00-08">camel-core</feature>
<feature version="4.4.1-fuse-00-08">camel-springosgi</feature>
<feature version="4.4.1-fuse-00-08">servicemixcamel</feature>
</feature>
</features>
(5) 添加OSGi configuration to the feature
如果应用程序使用了OSGi Configuration Admin Service,那么可以给feature添加config元素进行
配置,例如下面的例子指定了prefix属性有一个值MyTransform:
<?xml version="1.0" encoding="UTF-8"?>
<features>
<feature name="example-camel-bundle">
<config name="org.fusesource.fuseesb.example" >
prefix=MyTransform
</config>
</feature>
</features>
下面的列子演示使用上面的配置:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ctx="http://www.springframework.org/schema/context"
xmlns:osgi="http://camel.apache.org/schema/osgi"
xmlns:osgix="http://www.springframework.org/schema/osgicompendium"
...>
...
<bean id="myTransform" class="org.fusesource.fuseesb.example.MyTransform">
<property name="prefix" value="${prefix}"/>
</bean>
<osgix:cm-properties id="preProps" persistentid="org.fusesource.fuseesb.example">
<prop key="prefix">DefaultValue</prop>
</osgix:cm-properties>
<ctx:property-placeholder properties-ref="preProps" />
</beans>
${prefix}的值为:MyTransform.
2. 部署一个Feature
(1) 安装
features:refreshUrl
其次执行
(2) 卸载
features:uninstall example-camel-bundle
features:removerepository CustomFeatureRepository
(3) 热部署
Copy Feature repository至ServiceMix安装目录下的deploy目录,热部署时推荐重新定义一个简化的
feature repository:
<?xml version="1.0" encoding="UTF-8"?>
<features name="CustomDescriptor">
<repository>C:/ServiceMix-Features/features.xml</repository>
<feature name="hot-example-camel-bundle">
<feature>example-camel-bundle</feature>
</feature>
</features>
(4) 添加一个Feature至boot configuration
如果期望提供Apache Karaf的Copy 部署在多个主机上,那么可以添加一个feature至boot
configuration, 当Karaf第一次启动时将决定哪些是已经安装的features的集合。可修改安装
目录etc下的org.apache.karaf.features.cfg文件,在该文件中:
featuresRepositories指定在启动时要加载的feature repository;
featuresBoot指定在启动时要安装的feature.