ServiceMix中部署:OSGi Bundle和Feature
http://springsfeng.iteye.com/blog/1392658
ServiceMix中部署:OSGi Bundle和Feature
- 博客分類:
- ESB-ServiceMix
部署單個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.
?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的ServiceMix中部署:OSGi Bundle和Feature的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OSGi Bundle之Hello Wo
- 下一篇: Unable to update ind