zoukankan      html  css  js  c++  java
  • 分布式服务框架HSF学习

    转载:http://googi.iteye.com/blog/1884754

    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:

    Xml代码  收藏代码
    1. <dependency>  
    2.             <groupId>com.taobao.hsf</groupId>  
    3.             <artifactId>hsf.connector.spring</artifactId>  
    4.             <version>xxx</version>  
    5.  </dependency>  

     而对于服务框架肯定是有服务提供者和消费者两种角色,在提供者方要做的工作包括:
    1. 将interface的代码打成Jar包,放进maven仓库中,供使用者下载使用,而具体代码实现则不需要放进jar包中,使用者只能调用,无法看见具体实现。
    2.在对应的HSF的配置文件里,将提供的服务提供出来(基于spring的bean配置):

    Xml代码  收藏代码
    1. <bean id="xxxServiceImpl" class="xxx.xxxServiceImpl" />  
    2. <bean id="xxxServiceProvider"     class="com.taobao.hsf.app.spring.util.HSFSpringProviderBean" init-method="init">  
    3.      <property name="serviceInterface">  
    4.         <value>xxx.xxxService</value>  
    5.      </property>  
    6.      <property name="target">  
    7.         <ref bean="xxxServiceImpl" />  
    8.      </property>  
    9.      <property name="serviceName">  
    10.         <value>xxxService</value>  
    11.      </property>  
    12.      <property name="serviceVersion">  
    13.         <value>xxx</value>  
    14.      </property>  
    15.      <property name="serviceGroup">  
    16.         <value>HSF</value>  
    17.      </property>  
    18. </bean>  

     服务提供成功后,在HSF服务管理中心可以查看到这个HSF服务。
    而在消费者方要做的工作:

    Xml代码  收藏代码
    1. <bean name="xxxService" class="com.taobao.hsf.app.spring.util.HSFSpringConsumerBean" init-method="init">  
    2.      <property name="interfaceName" value="xxx.xxxService" />  
    3.      <property name="version" value="xxx" />  
    4. </bean>  

     这样这个service就可以使用了。

    HSF的缺点是其要使用指定的JBoss等容器,还需要在JBoss等容器中加入sar包扩展,对用户运行环境的侵入性大,如果你要运行在Weblogic或Websphere等其它容器上,需要自行扩展容器以兼容HSF的ClassLoader加载。 taobao有类似的其他框架Dubbo,介绍见
    http://www.iteye.com/magazines/103

  • 相关阅读:
    linux服务器git pull/push时提示输入账号密码之免除设置
    如何查看Linux发行版本
    pm2日志切割
    CentOS下配置redis允许远程连接
    Node.js对SQLite的async/await封装
    Linux 系统命令行下,对 SQLite3 数据库使用的一般操作
    CentOS 7下使用n工具更新Node.js
    英语原理,索引
    词根词缀,非核心prefix/suffix/root
    哲学家核心价值观
  • 原文地址:https://www.cnblogs.com/ceshi2016/p/7198135.html
Copyright © 2011-2022 走看看