当前位置:网站首页>Microservice governance (nocas)
Microservice governance (nocas)
2022-06-26 12:17:00 【Zhong Wan TK】
Implement microservice governance (Nocas)
1、 Introduction to service governance
Implement calls between microservices , We can go through HTTP Client tools complete , But we need to put the network address of the service provider (IP, port ) And so on , There will be the following problems :
- Once the service provider address changes , You need to modify the code manually
- Once there are multiple service providers , Unable to implement load balancing function
- Once services become more and more , It is difficult to maintain the call relationship manually
So what should be done , At this time, we need to dynamically implement service governance through the registry .
What is service governance
Service governance is the core and basic module of microservice architecture . It is used to realize the automatic registration and discovery of various micro services .
- ** Service registration :** In the service governance framework , Will build a registry , Each service unit registers the details of its own services with the registry . And form a list of services in the registry , The service registry needs to monitor whether the services in the list are available by heartbeat , If not available , You need to eliminate unavailable services from the service list .
- ** Service discovery :** The service invoker consults the service registry , And get the instance list of all services , Achieve access to specific service instances .

Through the call graph above, you will find , Besides microservices , Another component is the service registry , It is a very important component of the microservice architecture , In the microservice architecture, it mainly plays a role of coordinator . The registry generally includes the following functions :
1、 Service discovery
** Service registration :** Keep information about service providers and service callers
** Service subscription :** The service caller subscribes to the service provider's information , The registry pushes the provider's information to subscribers
2、 Service configuration
** Configure subscription :** Service providers and service callers subscribe to microservice related configurations
** Configure distribution :** Actively push configuration to service providers and service callers
3、 Service health testing
Testing the health of service providers , If an exception is found , Execute the service
Common registries
Zookeeper
Zookeeper Is a distributed services framework , yes Apache Hadoop A subproject of , It is mainly used to solve some data management problems often encountered in distributed applications , Such as : Unified naming service 、 State synchronization service 、 Cluster management 、 Management of distributed application configuration items .
Eureka
Eureka yes Spring Cloud Netflix Important components in , The main function is to do service registration and discovery . But now The source has been closed .Consul
Consul Is based on Go Open source tools for language development , Mainly for distributed , The service system provides service registration , Service discovery and configuration management .Consul The functions of are very practical , These include : Service registration / Find out 、 Health detection 、Key/Value Storage 、 Multi data center and distributed consistency guarantee .Consul Itself is just a binary executable , So the installation and deployment are very simple , Just download it from the official website , After executing the corresponding startup script .
Nacos
Nacos It is a dynamic service discovery that is easier to build cloud native applications 、 Configuration management and service management platform . He is Spring Cloud Alibaba One of the components , Responsible for service registration discovery and service configuration , Think of it this way nacos=eureka + config
2、Nacos brief introduction
Nacos Committed to helping discover 、 Configure and manage microservices .Nacos Provides a set of features that are easy to use , Help to quickly realize dynamic service discovery 、 Service configuration 、 Service metadata and traffic management .
As can be seen from the above introduction ,nacos It's a registry , It is used to manage various microservices from registrants .
3、Nacos Practical introduction
3.1、 build Nacos Environmental Science
The first 1 Step : install nacos
Download address :https://github.com/alibaba/nacos/releases, download zip Format installation package , Decompress after the user .
The first 2 Step : start-up nacos
## Toggle directory cd nacos/bin## Start command startup.cmd -m standalone
The first 3 Step : visit nacos
Open the browser and type http://localhost:8848/nacos, Access to services , The default password is nacos/nacos

3.2、 Register the microservice to Nacos
The first 1 Step : In global public pom.xml Add the following version dependency management to
<!-- Inherit Springboot The parent project , To limit Springboot edition , Be careful :SpringBoot The version must be alibaba cloud Supported versions -->
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.2.1.RELEASE</version>
</parent>
<dependencies>
<!-- Manual introduction Springboot rely on -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</dependency>
</dependencies>
<!-- introduce alibaba Parent project version limit for -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
The first 2 Step : stay pom.xml Add Nacos Dependence
<!--nacos client -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
The first 3 Step : Add on the startup class @EnableDiscoveryClient annotation
The first 4 Step : stay application.yml Add nacos Address of service
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: user-service
The first 4 Step : Start the service , see Nacos Is there a registered microservice in the control panel of
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-XVJBYsS1-1632881640556)(%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%A1%86%E6%9E%B6.assets/image-20210505105258418.png)]
The first 1 Step : In global public pom.xml Add the following version dependency management to
<!-- Inherit Springboot The parent project , To limit Springboot edition , Be careful :SpringBoot The version must be alibaba cloud Supported versions -->
<parent>
<artifactId>spring-boot-starter-parent</artifactId>
<groupId>org.springframework.boot</groupId>
<version>2.2.1.RELEASE</version>
</parent>
<dependencies>
<!-- Manual introduction Springboot rely on -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
</dependency>
</dependencies>
<!-- introduce alibaba Parent project version limit for -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
The first 2 Step : stay pom.xml Add Nacos Dependence
<!--nacos client -->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
The first 3 Step : Add on the startup class @EnableDiscoveryClient annotation
The first 4 Step : stay application.yml Add nacos Address of service
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: user-service
The first 4 Step : Start the service , see Nacos Is there a registered microservice in the control panel of 
3.3、 Service configuration center Nacos
First step : Introduce dependencies
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!-- send bootstrap To configure ⽂ Pieces of ⽣ effect -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
The second step : Create written bootstrap.yaml⽂ Pieces of
spring:
cloud:
nacos:
config:
server-addr: localhost:8848
file-extension: yaml
application:
name: user-service
profiles:
active: dev
A detailed version
spring.cloud.nacos.config.server-addr=192.168.0.139:8849
#spring.cloud.nacos.config.group=DEFAULT_GROUP
spring.cloud.nacos.config.namespace = 2a3c21b4-94cf-4ce9-9cf5-2d05b44f0eaa
spring.cloud.nacos.config.file-extension = properties
spring.cloud.nacos.discovery.server-addr=192.168.0.139:8849
spring.cloud.nacos.discovery.namespace= 2a3c21b4-94cf-4ce9-9cf5-2d05b44f0eaa
spring.cloud.nacos.discovery.service=${
spring.application.name}
The third step : stay nacos Create the specified profile on
name :user-service-dev.yaml

Step four : Confirm release
边栏推荐
- Re recognized! Know that Chuangyu has been selected as one of the first member units of the "business security promotion plan"
- 修改calico网络模式为host-gw
- UDP protocol details [easy to understand]
- MS17_ 010 utilization summary
- 汇编语言(7)运算指令
- Is it safe to open a securities account
- Build document editor based on slate
- 开通证券账户需要注意事项 开户安全吗
- 统计遗传学:第二章,统计分析概念
- [graduation season · advanced technology Er] I remember the year after graduation
猜你喜欢

11、 Box styles and user interface

【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构

Quantitative elementary -- akshare obtains stock code, the simplest strategy

Re recognized! Know that Chuangyu has been selected as one of the first member units of the "business security promotion plan"

This paper introduces the simple operation of realizing linear quadratic moving average of time series prediction that may be used in modeling and excel

Loggie encoding and newline character test

统计遗传学:第一章,基因组基础概念

Black squares in word

This executeQuery (SQL) cannot compile classes for JSP. What is the reason?

介紹一下實現建模中可能用到的時間序列預測之線性二次移動平均,Excel的簡單操作
随机推荐
Lintcode 130 · stacking
2022 China smart bathroom cabinet Market Research and investment Competitiveness Analysis Report
【Redis 系列】redis 学习十六,redis 字典(map) 及其核心编码结构
PolarisMesh系列文章——概念系列(一)
What should I do from member labels to portraits?
Deep thinking from senior member managers
The most complete kubernetes core command of the latest version so far
Re recognized! Know that Chuangyu has been selected as one of the first member units of the "business security promotion plan"
Scala-day01- companion objects and HelloWorld
Scala-day02- variables and data types
1、 MySQL introduction
Excel operation of manual moving average method and exponential smoothing method for time series prediction
[graduation season · advanced technology Er] I remember the year after graduation
Several problems encountered in setting up the environment in the past two days
Refined operation, extending the full life cycle value LTV
18: Chapter 3: development of pass service: 1: SMS login & registration process, introduction; (SMS verification code is used here)
Flannel's host GW and calico
Prospering customs through science and technology, Ronglian and Tianjin Customs jointly build a genomic database and analysis platform
webgame开发中的文件解密
Oracle lock table query and unlocking method