当前位置:网站首页>9. Openfeign service interface call
9. Openfeign service interface call
2022-06-28 01:37:00 【Bitter candy】
Study B Standing still, Mr. Zhou Yang of Silicon Valley SpringCloud The lecture notes
1. summary
1.1 OpenFeign What is it? ?
Feign It's a declarative one web Service client , Let's write web Service clients become very easy , Just create an interface and annotate it
GitHub:https://github.com/spring-cloud/spring-cloud-openfeign
1.2 What can I do?
1.3Feign and OpenFeign Difference between them
2.OpenFeign Use steps
2.1 newly build cloud-consumer-feign-order80
Feign Use... On the consumer side
Interface + annotation Microservice invocation interface [email protected]
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>cloud2020</artifactId>
<groupId>com.atguigu.springcloud</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-consumer-feign-order80</artifactId>
<!--openfeign-->
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>com.atguigu.springcloud</groupId>
<artifactId>cloud-api-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
2.3 Change yml
server:
port: 80
eureka:
client:
register-with-eureka: false
service-url:
defaultZone: http://eureka7001.com:7001/eureka, http://eureka7002.com:7002/eureka
2.4 Main startup class annotation @EnableFeignClients
@SpringBootApplication
@EnableFeignClients
public class OrderFeignMain80 {
public static void main(String[] args) {
SpringApplication.run(OrderFeignMain80.class,args);
}
}
2.5 Business class
Business logic interface [email protected] Configuration call provider service
newly build PaymentFeignService Interface and add comments @FeignClient
@Component
@FeignClient(value = "CLOUD-PAYMENT-SERVICE")
public interface PaymentFeignService {
@GetMapping(value = "/payment/get/{id}")
public CommonResult getPaymentById(@PathVariable("id") Long id);
}
@RestController
public class OrderFeignController {
@Resource
private PaymentFeignService paymentFeignService;
@GetMapping(value = "/consumer/payment/get/{id}")
public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id){
return paymentFeignService.getPaymentById(id);
}
}
2.6 test
Start... First 2 individual eureka colony 7001/7002, Restart 2 Micro services 8001/8002, start-up OpenFeign start-up
http://localhost/consumer/payment/get/3
Feign Load balancing item with its own configuration
summary :
3.OpenFeign Timeout control and log printing function
3.1 Timeout control
OpenFeign By default, wait one second , Report error after exceeding
OpenFeign The default support Ribbon
YML The file needs to be opened OpenFeign Client timeout control , namely ribbon Timeout control for
ribbon:
ReadTimeout: 5000 # The time it takes to read available resources from the server after the connection is established
ConnectTimeout: 5000 # The time it takes to establish a connection , It is suitable for normal network conditions , The time taken to connect the two ends
3.2 Log printing
The level of logging :
Write configuration class
@Configuration
public class FeignConfig {
@Bean
Logger.Level feignLoggerLevel(){
return Logger.Level.FULL;
}
}
Change yml
logging:
level:
com.atguigu.springcloud.service.PaymentFeignService: debug
Background view
边栏推荐
- Want to open an account to buy stock, is it safe to open an account on the Internet?
- Web mouse click special effects case collection (red heart in live broadcast room)
- PostgreSQL设置自增字段
- 零基础多图详解图神经网络
- PostgreSQL setting auto increment field
- Deepmind | pre training of molecular property prediction through noise removal
- What is the e-commerce conversion rate so abstract?
- Comprehensive evaluation of free, easy-to-use and powerful open source note taking software
- Adobe Premiere基础-编辑素材文件常规操作(脱机文件,替换素材,素材标签和编组,素材启用,便捷调节不透明度,项目打包)(十七)
- Set collection usage
猜你喜欢
Overview and deployment of GFS distributed file system
Latest MySQL advanced SQL statement Encyclopedia
【嵌入式基础】串口通信
什么是过孔式导电滑环?
Taro--- day1--- construction project
Proe/Creo产品结构设计-钻研不断
Why stainless steel swivel
Réseau neuronal pour la solution détaillée Multi - diagrammes de fondation zéro
FB、WhatsApp群发消息在2022年到底有多热门?
[untitled]
随机推荐
Golang monkeys eat peaches and ask for the number of peaches on the first day
大尺寸导电滑环市场应用强度如何
什么是过孔式导电滑环?
Ten thousand words long article understanding business intelligence (BI) | recommended collection
Electron window background transparent borderless (can be used to start the page)
Introduction to memory model of JVM
Huawei partners and Developers Conference 2022 | Kirin software cooperates with Huawei to jointly build the computing industry and create a digital intelligence future
PostgreSQL设置自增字段
Import the data table in MySQL into Excel
Overview and deployment of GFS distributed file system
How to build dual channel memory for Lenovo Savior r720
What are the requirements for customizing the slip ring for UAV
Ten MySQL locks, one article will give you full analysis
单晶炉导电滑环的应用范围和作用是什么
electron窗口背景透明无边框(可用于启动页面)
I/O限制进程与CPU限制进程
SPuG - lightweight automatic operation and maintenance platform
【DNS 解析】将Name.com的域名接入DNSPod解析
Squid proxy server (Web cache layer for cache acceleration)
基于可学习尺寸自适应分子亚结构的药物相互作用预测