当前位置:网站首页>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)


边栏推荐
- 古瑞瓦特沖刺港交所上市:創下“多個第一”,獲IDG資本9億元投資
- Bifu divides EtherCAT module into multiple synchronization units for operation -- use of sync units
- 【MySQL从入门到精通】【高级篇】(二)MySQL目录结构与表在文件系统中的表示
- Update and download of Beifu EtherCAT XML description file
- MongoDB系列之Window环境部署配置
- 输入文本自动生成图像,太好玩了!
- Network remote access using raspberry pie
- Here Document免交互及Expect自动化交互
- Wechat applet -picker component is repackaged and the disabled attribute is added -- below
- mysql配置提高数据插入效率
猜你喜欢

HW蓝队溯源流程详细整理

Zero basics of C language lesson 7: break & continue

Mysql database explanation (III)

LAMP编译安装

Network remote access using raspberry pie

Beifu PLC model selection -- how to see whether the motor is a multi turn absolute value encoder or a single turn absolute value encoder

What is the use of index aliases in ES

Thinking caused by the error < note: candidate expectations 1 argument, 0 provided >

Detailed sorting of HW blue team traceability process

Es sauvegarde et restauration des données par instantané
随机推荐
A primary multithreaded server model
Awk tools
MySQL explanation (I)
KITTI Tracking dataset whose format is letf_ top_ right_ bottom to JDE normalied xc_ yc_ w_ h
GO语言-管道channel
Some conclusions about Nan
Wechat applet - bind and prevent event bubble catch
d检查类型是指针
What features are added to Photoshop 2022 23.4.1? Do you know anything
7-2 the cubic root of a number
Teacher Li Hang's new book "machine learning methods" is on the market! Purchase link attached
Here Document免交互及Expect自动化交互
33. Use rgbd camera for target detection and depth information output
MySQL explanation (II)
Network remote access using raspberry pie
Beifu twincat3 can read and write CSV and txt files
LAMP编译安装
ES基于Snapshot(快照)的数据备份和还原
Echart stack histogram: add white spacing effect setting between color blocks
李航老师新作《机器学习方法》上市了!附购买链接