当系统进行升级时,一般都是采用“灰度发布(又称为金丝雀发布)”过程。即在低压力时段,让部分消费者先调用新的提供者实现类,其余的仍然调用老的实现类,在新的实现类运行没有问题的情况下,逐步让所有消费者全部调用成新的实现类。多版本控制就是实现灰度发布的
一、创建提供者04-provider-version
(1) 创建工程
创建Maven的工程。
(2) 导入依赖
Spring的版本为4.3.16
需要的依赖有:
- dubbo2.7.0版本依赖
- zk客户端curator依赖
- servlet与jsp依赖
- spring相关依赖
- spring需要的commons-logging依赖
- 自定义00-api依赖
- <dependencies>
- <!-- zk客户端依赖:curator -->
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-recipes</artifactId>
- <version>2.13.0</version>
- </dependency>
- <dependency>
- <groupId>org.apache.curator</groupId>
- <artifactId>curator-framework</artifactId>
- <version>2.13.0</version>
- </dependency>
-
- <!--业务接口工程依赖-->
- <dependency>
- <groupId>00-api</groupId>
- <artifactId>00-api</artifactId>
- <version>1.0-SNAPSHOT</version>
- </dependency>
-
- <!-- dubbo依赖 -->
- <dependency>
- <groupId>org.apache.dubbo</groupId>
- <artifactId>dubbo</artifactId>
- <version>2.7.0</version>
- </dependency>
- <!-- Spring依赖 -->
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- <version>${spring-version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- <version>${spring-version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-context</artifactId>
- <version>${spring-version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-expression</artifactId>
- <version>${spring-version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aop</artifactId>
- <version>${spring-version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-aspects</artifactId>
- <version>${spring-version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-tx</artifactId>
- <version>${spring-version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-jdbc</artifactId>
- <version>${spring-version}</version>
- </dependency>
- <!-- commons-logging依赖 -->
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- <version>1.2</version>
- </dependency>
-
- </dependencies>
(3)定义两个接口实现类
(4)修改配置文件
resourcesMETA-INFspringspring-provider.xml目录
指定版本0.0.1对应的是oldService实例,而版本0.0.2对应的是newService实例
二、创建消费者04-consumer-version
(1) 创建工程
(2) 导入依赖
和提供者一样
(3) 创建消费者
(4) 修改配置文件