当前位置:网站首页>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 
边栏推荐
- Review of drug discovery-02-prediction of molecular properties
- How about the market application strength of large-size conductive slip rings
- 【说明】Jmeter乱码的解决方法
- Deploy a mongodb single node server locally, enable auth authentication and enable oplog
- Overview and deployment of GFS distributed file system
- Import the data table in MySQL into Excel
- 力扣今日题-522. 最长特殊序列
- .mp4视频测试地址
- 零基礎多圖詳解圖神經網絡
- Taro---day1---搭建项目
猜你喜欢

零基础多图详解图神经网络

Taro---day2---编译运行

Meituan dynamic thread pool practice idea has been open source

联想拯救者R720如何组建双通道内存

N methods of data De duplication using SQL

Overview of drug discovery-01 overview of drug discovery

Xctf attack and defense world misc wage earner advanced zone

美团动态线程池实践思路已开源

药物发现综述-01-药物发现概述

【嵌入式基础】串口通信
随机推荐
Cloud native O & M article plan
golang 猴子吃桃子,求第一天桃子的数量
数据人面试指南 | 准备好这几点做到有备无患!
N methods of data De duplication using SQL
如何在您的Shopify商店中添加实时聊天功能?
Qu'est - ce que la numérisation? Qu'est - ce que la transformation numérique? Pourquoi les entreprises choisissent - elles la transformation numérique?
PostgreSQL setting auto increment field
免费、好用、强大的开源笔记软件综合评测
Li Kou today's question -522 Longest special sequence
Taro---day1---搭建项目
同花顺股票开户是会有什么风险吗?同花顺开户安全吗
Set collection usage
Download, configuration and installation of MySQL
MapReduce elementary programming practice
FB、WhatsApp群发消息在2022年到底有多热门?
What is digitalization? What is digital transformation? Why do enterprises choose digital transformation?
LMSOC:一种对社会敏感的预训练方法
[open source] open source system sorting - Examination Questionnaire, etc
Message Oriented Middleware for girlfriends
Some problems in awk