http://springsfeng.iteye.com/blog/1392658
部署单个Bundle:
1. Hot Deployment
Copy JAR文件至ServiceMix安装目录下的deploy 目录下即可。
Linux下命令:cp ProjectDir/target/foo-1.0-SNAPSHOT.jar InstallDir/deploy
2. 手动部署
(1) osgi:install , 例如:osgi:install -s file:ProjectDir/target/foo-1.0-SNAPSHOT.jar
(2) osgi:list ,查看已经安装的Bundle。
(3) osgi:uninstall 181 , Uninstall Bundle 181.
(4) osgi:resolve 181 , 解析Bundle181的依赖是否满足。
(5) osgi:start 181 182 183 , 启动三个Bundle.
(6) osgi:stop 181 182 183 , 停止三个Bundle.
(7) osgi:restart 181 182 183 , 重启三个Bundle.
3. 设置Bundle Start Level
Bundle的Start Level是一个正数,Bundle 的启动级别越低Bundle越优先启动。
(1) osgi:bundel-level 60 182 ,设置Bundle181,182的启动级别为60。
(2) osgi:start-level ,查看系统的Start Level,默认为100; 可通过osgi:start-level 200,设置为200.
部署多个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 , 强制FuseESB内核重新读取所有的feature repository;
其次执行 :features:install example-camel-bundle
(2) 卸载
卸载feature:features:uninstall example-camel-bundle
卸载feature repository: 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.