当前位置:网站首页>7.consul service registration and discovery
7.consul service registration and discovery
2022-06-26 13:44:00 【Bitter candy】
Study B Standing still, Mr. Zhou Yang of Silicon Valley SpringCloud The lecture notes
1. Consul brief introduction
1.1 What is it?

1.2 What can I do?
Service discovery : Provide HTTP and DNS Two ways of discovery
Health monitoring : Support multiple protocols ,HTTP、TCP、Docker、Shell Script customization
KV Storage :key , Value Storage mode
Multi-data center :Consul Support multiple data centers
visualization Web Interface
Official website :https://www.consul.io/intro/index.html
Download address :https://www.consul.io/downloads.html
Chinese document :https://www.springcloud.cc/spring-cloud-consul.html
1.3 Install and run Consul
After downloading, there is only one consul.exe file , Double click on the hard disk path to run , View version information 

Use development mode to start :consul agent -dev
You can access... Through the following address Consul Home page :http://localhost:8500

2. newly build Module Payment services provider8006
2.1 newly build module cloud-providerconsul-payment8006
2.2 Change pom
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springcloud2020</artifactId>
<groupId>com.atguigu.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-providerconsul-payment8006</artifactId>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-consul-discovery -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.atguigu.springcloud</groupId>
<artifactId>cloud-api-commons</artifactId>
<version>${project.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
2.3 Change yml
server:
port: 8006
spring:
application:
name: consul-provider-payment
cloud:
consul:
host: localhost
port: 8500
discovery:
service-name: ${
spring.application.name}
2.4 Startup class and business class
@SpringBootApplication
@EnableDiscoveryClient
public class PaymentMain8006 {
public static void main(String[] args) {
SpringApplication.run(PaymentMain8006.class,args);
}
}
@RestController
@Slf4j
public class PaymentController {
@Value("${server.port}")
private String serverPort;
@GetMapping(value = "/payment/consul")
public String paymentConsul(){
return "springcloud with consul: "+serverPort+"\t"+ UUID.randomUUID().toString();
}
}
2.5 Verification test
http://localhost:8006/payment/consul
3. newly build Module Consumer service order8006
3.1 newly build Modulecloud-consumerconsul-order80
3.2 Change pom
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-consul-discovery -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
</dependency>
<dependency>
<groupId>com.atguigu.springcloud</groupId>
<artifactId>cloud-api-commons</artifactId>
<version>${project.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-devtools -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
3.3 Change yml
server:
port: 80
spring:
application:
name: consul-consumer-order
cloud:
consul:
host: localhost
port: 8500
discovery:
service-name: ${
spring.application.name}
3.4 Startup class and business class
@SpringBootApplication
@EnableDiscoveryClient
public class OrderConsulMain80 {
public static void main(String[] args) {
SpringApplication.run(OrderConsulMain80.class,args);
}
}
@Configuration
public class ApplicationContextConfig {
@LoadBalanced
@Bean
public RestTemplate getRestTemplate(){
return new RestTemplate();
}
}
@RestController
@Slf4j
public class OrderConsulController {
public static final String INVOME_URL = "http://consul-provider-payment";
@Resource
private RestTemplate restTemplate;
@GetMapping("/consumer/payment/consul")
public String payment (){
String result = restTemplate.getForObject(INVOME_URL+"/payment/consul",String.class);
return result;
}
}
3.5 Verification test
http://localhost/consumer/payment/consul
4. The similarities and differences between the three registries
4.1CAP theory
C:Consistency( Strong consistency )
A:Availability( Usability )
P:Partition tolerance( Partition fault tolerance )
CAP Theory focuses on granularity is data , Rather than the overall system design strategy 

4.2 The similarities and differences between the three registries

4.2.1AP(Eureka)


4.2.2 CP(Zookeeper/Consul)


边栏推荐
- Lamp compilation and installation
- Ubuntu installation and configuration PostgreSQL (18.04)
- Zero basics of C language lesson 8: Functions
- 2021-10-09
- GC is not used in D
- Nexys A7开发板资源使用技巧
- MySQL讲解(二)
- Bifu divides EtherCAT module into multiple synchronization units for operation -- use of sync units
- 古瑞瓦特沖刺港交所上市:創下“多個第一”,獲IDG資本9億元投資
- Teacher Li Hang's new book "machine learning methods" is on the market! Purchase link attached
猜你喜欢

微信小程序注册指引

Tips for using nexys A7 development board resources

Zero basics of C language lesson 7: break & continue

Embedded virlog code running process

基于PyTorch的生成对抗网络实战(7)——利用Pytorch搭建SGAN(Semi-Supervised GAN)生成手写数字并分类

Firewall introduction

Basic type of typescript

MySQL explanation (II)

Generation and rendering of VTK cylinder

Pytorch based generation countermeasure Network Practice (7) -- using pytorch to build SGAN (semi supervised GaN) to generate handwritten digits and classify them
随机推荐
Global variable vs local variable
Generation and rendering of VTK cylinder
Firewall introduction
Solutions to the failure of last child and first child styles of wechat applet
imagecopymerge
H5 video automatic playback and circular playback
Wechat applet -picker component is repackaged and the disabled attribute is added -- above
MongoDB系列之适用场景和不适用场景
Network remote access using raspberry pie
Mongodb series window environment deployment configuration
Taishan Office Technology Lecture: four cases of using bold font
[how to connect the network] Chapter 2 (middle): sending a network packet
Original code, inverse code and complement code
7-2 the cubic root of a number
Exercise set 1
Design of simple digital circuit traffic light
HW蓝队溯源流程详细整理
李航老师新作《机器学习方法》上市了!附购买链接
33、使用RGBD相机进行目标检测和深度信息输出
Create your own cross domain proxy server