First acquaintance with Feign service call

First of all, what is Feign?

Simply put:

 Previously, ribbon+restTemplate was used to achieve load balancing + service invocation. Now Feign can be used directly. Because Feign integrates Ribbon internally, Feign also has a client-side load balancing function. Feign implements remote invocation of services through annotations.

Feign integrates ribbon:

Technical replacement diagram:

One: How to do it? Idea map:

 1). Consumer's dependence:

2). Startup class: @EnableFeignClients activate to open feign

 3.) In the service of the consumer side, write the corresponding interface of the provider side to be called, and add the @FeignClient annotation

4). The consumer-side controller calls the previous step on the consumer-side, service interface:

In this way, you can directly call the provider's interface. The main points are two annotations, the start class @EnableFeignClients, and the service layer @FeignClient annotations 

Two: feign timeout control, the default is 1s, timeout will report an error, this can be set by yourself:

Three: Log:

1 Introduction:

 

2). config class, pay special attention to the Logger package:

3).yml configuration file:

 

4). Effect display:

Summary: That is, the consumer calls the provider's interface for use, and the two annotations are over. 

Guess you like

Origin blog.csdn.net/zhangleiyes123/article/details/106800719