[Springcloud] Detailed Feign (service call)

Here Insert Picture Description
Today we are talking about Springcloud the fourth component - manure, not, Feign.

What Feign that?

Feign effect of:
(1) is a declarative, template-based HTTP client that can help us more quickly and gracefully invoke HTTP API.
(2) and which is capable of integrating Ribbon Hystrix.

  • Ribbon: implementation of the client load balancing service calls
  • Hystrix: through the circuit breaker to protect the micro-service applications

Here Insert Picture Description

Ribbon Configuration

Feign client load balancing is achieved through the Ribbon, so we can directly define the parameters of the various service client calls by configuring the client Ribbon way.

Related

//全局配置
ribbon.ConnectTimeout=500
ribbon.ReadTimeout=5000

//指定服务配置
HELLO-SERVICE.ribbon.ConnectTimeout=500
HELLO-SERVICE.ribbon.ReadTimeout=5000
HELLO-SERVICE.ribbon.OkToRetryOnAllOperations=true
HELLO-SERVICE.ribbon.MaxAutoRetriesNextServer=2
HELLO-SERVICE.ribbon.MaxAutoRetries=1

Retry mechanism

Feign and Ribbon, there are also the default retry mechanism request.

Hystrix arrangement

By default, Feign Feign clients will all methods are encapsulated in order to carry out Hystrix service protection.

Related

//设置全局的超时时间
Hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=5000


// 全局关闭Hystrix功能
feign.hystrix.enabled=false

// 对某个服务客户端进行关闭
@Scope(“prototype”)

Service downgraded configuration

(1) preparation of the interface is defined Feign client interface a specific category
(2) in the service binding interface to specify the implementation class corresponding to the service degradation by @FeignClient (fallback = xxx)

Other configurations

Compression request

Request and response GZIP compression to reduce performance losses during communication. parameter settings:

feign.compression.request.enabled=true
feign.compression.response.enabled=true

Logging Configuration

(1) open:

logging.level.com.didispace.web.HelloService=DEBUG

(2) the non-object definition Logger.Level none level.

  • none: No information is logged
  • basic: Only requests recording method, URL, and the response status code and execution time
  • headers: also the head of the information request and response
  • full: record details of all requests and responses, including header information, request body, metadata, etc.
summary

Note that, the Ribbon "time out" and Hystrix the "time out" different, Ribbon after a timeout, it will retry after a timeout Hystrix will be blown. So Hystrix timeout should be greater than the timeout Ribbon.

Published 258 original articles · won praise 769 · views 340 000 +

Guess you like

Origin blog.csdn.net/qsbbl/article/details/97684025