Dubbo 是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,以及SOA服务治理方案。是阿里巴巴 SOA 服务化治理方案的核心框架。其核心部分包含:
1、远程通讯:提供对多种基于长连接的NIO框架抽象封装,包括多种线程模型,序列化,以及“请求-响应”模式的信息交换方式。
2、集群容错:提供基于接口方法的透明远程过程调用,包括多协议支持,以及软负载均衡,失败容错,地址路由,动态配置等集群支持。
3、自动发现:给予注册中心目录服务,使服务消费放能动态的查找服务提供方,是抵制透明,是服务提供方可以平滑增加或减少机器。
Dubbo 采用全Spring配置方式,透明化接入应用,对应用没有任何API侵入,只需用Spring加载Dubbo的配置即可,Dubbo基于Spring的Schema扩展进行加载。根据Dubbo官网上的介绍,配置Dubbo有四种方式,分别是:xml配置文件、properties配置文件、annotation配置、API配置四种。
1、XML 配置文件方式
创建 DubboDemo 项目,并创建 interface 模块、provider 模块、consumer 模块,它们都是 DubboDemo 的子模块。其中 interface 模块存放所有的接口、provider 模块提供服务、consumer 消费服务。在 DubboDemo 模块 pom.xml 加入如下依赖,为所有模块提供 JUnit 和 LOG4J 依赖。
<!-- **************************** Properties 配置 **************************** -->
<properties>
<junit.version>3.8.1</junit.version>
</properties>
<!-- **************************** /Properties 配置 **************************** -->
<dependencies>
<!-- **************************** JUnit 依赖 **************************** -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- **************************** /JUnit 依赖 **************************** -->
<!-- **************************** 日志 依赖 **************************** -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.6</version>
</dependency>
<!-- **************************** /日志 依赖 **************************** -->
</dependencies>
在 interface 模块中创建接口 com.lwz.ssm.service.IUserService
创建