HSF提供的是分佈式服務開發框架,taobao內部使用較多,總體來說其提供的功能及一些實現基礎:
1.標準Service方式的RPC
1)、Service定義:基於OSGI的Service定義方式
2)、TCP/IP通信:
IO方式:nio,採用mina框架
連接方式:長連接
服務器端有限定大小的連接池
WebService方式
3)、序列化:Hessian序列化機制
2.軟件負載體系
3.模塊化、動態化
4.服務治理
這裏簡單介紹下其使用:
首先要將HSF功能加進工程,是maven的話,在pom.xml裏要依賴HSF:
- <dependency>
- <groupId>com.taobao.hsf</groupId>
- <artifactId>hsf.connector.spring</artifactId>
- <version>xxx</version>
- </dependency>
而對於服務框架肯定是有服務提供者和消費者兩種角色,在提供者方要做的工作包括:
1. 將interface的代碼打成Jar包,放進maven倉庫中,供使用者下載使用,而具體代碼實現則不需要放進jar包中,使用者只能調用,無法看見具體實現。
2.在對應的HSF的配置文件裏,將提供的服務提供出來(基於spring的bean配置):
- <bean id="xxxServiceImpl" class="xxx.xxxServiceImpl" />
- <bean id="xxxServiceProvider" class="com.taobao.hsf.app.spring.util.HSFSpringProviderBean" init-method="init">
- <property name="serviceInterface">
- <value>xxx.xxxService</value>
- </property>
- <property name="target">
- <ref bean="xxxServiceImpl" />
- </property>
- <property name="serviceName">
- <value>xxxService</value>
- </property>
- <property name="serviceVersion">
- <value>xxx</value>
- </property>
- <property name="serviceGroup">
- <value>HSF</value>
- </property>
- </bean>
服務提供成功後,在HSF服務管理中心可以查看到這個HSF服務。
而在消費者方要做的工作:
- <bean name="xxxService" class="com.taobao.hsf.app.spring.util.HSFSpringConsumerBean" init-method="init">
- <property name="interfaceName" value="xxx.xxxService" />
- <property name="version" value="xxx" />
- </bean>
這樣這個service就可以使用了。
HSF的缺點是其要使用指定的JBoss等容器,還需要在JBoss等容器中加入sar包擴展,對用戶運行環境的侵入性大,如果你要運行在Weblogic或Websphere等其它容器上,需要自行擴展容器以兼容HSF的ClassLoader加載。 taobao有類似的其他框架Dubbo,介紹見
http://www.iteye.com/magazines/103