一. dubbo简介

  dubbo是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架。

 

二. 架构

  引用dubbo的架构图:

dubbo的简单应用

  • Provider: 暴露服务的服务提供方。
  • Consumer: 调用远程服务的服务消费方。
  • Registry: 服务注册与发现的注册中心。
  • Monitor: 统计服务的调用次调和调用时间的监控中心。
  • Container: 服务运行容器。

三. 应用

  从上图可知dubbo存在两个基本的角色:服务提供者Provider和服务消费者Consumer。

  它的原理其实是dubbo服务提供者暴露出服务,然后消费者请求暴露的服务,由dubbo创建服务代理处理业务。其中接口服务是消费者和提供者共享的。

  下面列举一个最简单的项目来示例用法,项目示例使用maven构建。

  1. 服务提供者

  项目采用多模块构建,项目结构如下:

  dubbo的简单应用

  模块说明:

  common:共同享用的模块,一般存放domain或者常用的工具类。

  service: 暴露的service服务接口。

  service-impl: 服务的实现类,也就是业务层逻辑代码。

  web: 服务启动的模块,一般是项目配置和页面等。

  模块直接的关系如下图:

  dubbo的简单应用

  pom.xml仅引入了必须的jar包支持,且只应用在父模块的pom.xml:

  

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 3     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 4     <modelVersion>4.0.0</modelVersion>
 5     <groupId>com.bigbang</groupId>
 6     <artifactId>provider</artifactId>
 7     <version>0.0.1-SNAPSHOT</version>
 8     <packaging>pom</packaging>
 9     <name>注册中心</name>
10     <description>服务注册</description>
11     <properties>
12         <spring.version>3.2.4.RELEASE</spring.version>
13     </properties>
14     <dependencies>
15         <dependency>
16             <groupId>junit</groupId>
17             <artifactId>junit</artifactId>
18             <version>3.8.1</version>
19             <scope>test</scope>
20         </dependency>
21         <dependency>
22             <groupId>org.springframework</groupId>
23             <artifactId>spring-context</artifactId>
24             <version>${spring.version}</version>
25         </dependency>
26 
27         <dependency>
28             <groupId>org.springframework</groupId>
29             <artifactId>spring-core</artifactId>
30             <version>${spring.version}</version>
31         </dependency>
32 
33         <dependency>
34             <groupId>org.springframework</groupId>
35             <artifactId>spring-beans</artifactId>
36             <version>${spring.version}</version>
37         </dependency>
38 
39         <dependency>
40             <groupId>org.springframework</groupId>
41             <artifactId>spring-webmvc</artifactId>
42             <version>${spring.version}</version>
43         </dependency>
44         <dependency>
45             <groupId>com.alibaba</groupId>
46             <artifactId>dubbo</artifactId>
47             <version>2.5.3</version>
48         </dependency>
49     </dependencies>
50     <build>
51         <plugins>
52             <plugin>
53                 <groupId>org.apache.maven.plugins</groupId>
54                 <artifactId>maven-compiler-plugin</artifactId>
55                 <configuration>
56                     <source>1.8</source>
57                     <target>1.8</target>
58                 </configuration>
59             </plugin>
60         </plugins>
61         <finalName>service</finalName>
62     </build>
63     <modules>
64         <module>service</module>
65         <module>service-impl</module>
66         <module>common</module>
67         <module>web</module>
68     </modules>
69 </project>
pom.xml

相关文章:

  • 2021-05-05
  • 2021-12-17
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-11-09
  • 2021-10-25
猜你喜欢
  • 2021-11-14
  • 2021-05-24
  • 2021-05-28
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
相关资源
相似解决方案