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


边栏推荐
- 网络远程访问的方式使用树莓派
- DataGrip配置的连接迁移
- Es common grammar I
- A few lines of code can realize complex excel import and export. This tool class is really powerful!
- 【MySQL从入门到精通】【高级篇】(二)MySQL目录结构与表在文件系统中的表示
- [shell] generate strings between specified dates
- Traverse the specified directory to obtain the file name with the specified suffix (such as txt and INI) under the current directory
- Nlp-d60-nlp competition D29
- MongoDB系列之适用场景和不适用场景
- Bigint: handles large numbers (integers of any length)
猜你喜欢

2021-10-18 character array

Reprint - easy to use wechat applet UI component library

Teacher Li Hang's new book "machine learning methods" is on the market! Purchase link attached

Stack, LIFO

Mongodb series window environment deployment configuration

Here document interaction free and expect automatic interaction

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

Bifu divides EtherCAT module into multiple synchronization units for operation -- use of sync units

Generation and rendering of VTK cylinder

MySQL数据库讲解(三)
随机推荐
Wechat applet -picker component is repackaged and the disabled attribute is added -- above
7-2 picking peanuts
Sed editor
同花顺股票开户选哪个证券公司是比较好,比较安全的
输入文本自动生成图像,太好玩了!
Tips for using nexys A7 development board resources
Beifu PLC obtains system time, local time, current time zone and system time zone conversion through program
awk工具
【HCSD应用开发实训营】一行代码秒上云评测文章—实验过程心得
Select tag - uses the default text as a placeholder prompt but is not considered a valid value
PHP非对称加密算法(RSA)加密机制设计
Exercise set 1
Create your own cross domain proxy server
三维向量的夹角
mysql配置提高数据插入效率
Analysis of state transition diagram of Beifu NC axis
去某东面试遇到并发编程问题:如何安全地中断一个正在运行的线程
嵌入式virlog代码运行流程
防火墙介绍
Original code, inverse code and complement code