1 Overview
This article describes how based on Spring Boot 2.x version, by Nacos as configuration and registration center, implementation of the registration services and consumer Dubbo.
Integrated component release notes:
Spring Boot 2.1.9
Dubbo 2.7.3
Nacos 1.1.3
The article highlights:
- 1. Using yml way dubbo configuration.
- 2. the integration of related components using a newer version.
- 3. Related source placed on Github, can always see.
Source code is placed Github: https://github.com/raysonfang/spring-boot-demo-all
Before the company when using Dubbo 2.6.1, using Zookeeper as a registration center. At that time, only just take it and use as a registration center, a management background is no specific visualization management operations, and second, single function, use only as a registered center.
After learning and understanding through a period of time, found that the use of open source Nacos Ali as a registration center and external distribution center. Zookeeper it is more than suitable for registration and configuration services, after all, is a maker of open source, after a lot of practice.
If you do not know what Nacos is or what has the primary function of architecture and design. Take the time to check their own data.
nacos:
Note:此次主要实践Nacos作为注册中心,后面会单独整合Nacos作为配置中心的实践分享。
2, base frame structures
Use idea + maven to build a multi-module project
spring-boot-dubbo-nacos- demo: Parent Project
Service-Provider-Shop: Dubbo service provider
Consumer-Service-Shop: Dubbo service consumers, is a web project
3, pom.xml description
: the Spring-the Boot-Dubbo-nacos-Demo pom.xml parent project
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.raysonblog</groupId> <artifactId>misco-dubbo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>misco-dubbo</name> <packaging>pom</packaging> <description>Demo project for Spring Boot Dubbo Nacos</description> <modules> <module>shop-service-provider</module> <module>shop-service-consumer</module> </modules> <properties> <java.version>1.8</java.version> <spring-boot.version>2.1.9.RELEASE</spring-boot.version> <dubbo.version>2.7.3</dubbo.version> </properties> <dependencyManagement> <dependencies> <!-- Spring Boot --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- Apache Dubbo --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-dependencies-bom</artifactId> <version>${dubbo.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- Dubbo Spring Boot Starter --> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>${dubbo.version}</version> </dependency> <dependency> <groupId>org.apache.dubbo</groupId> <artifactId>dubbo</artifactId> <version>${dubbo.version}</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> <exclusion> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </dependencyManagement> <repositories> <repository> <id>apache.snapshots.https</id> <name>Apache Development Snapshot Repository</name> <url>https://repository.apache.org/content/repositories/snapshots</url> <releases> <enabled>false</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <