feign the configuration of ribbon
Mainly in the ribbon-core.jar Files, com.netflix.client.config package, which configure the default class DefaultClientConfigImpl
easiest way to configure the client and the load balancer is the property meets certain format:
. <ClientName> < namespace>. <propertyName> = < value>
may be defined as a property class path or file system attribute
default, "ribbon" should be namespace.
If no attribute is specified client, com.netflix.client.ClientFactory will still create the client and load balancer for all required attributes. The default value is specified as constants in this class.
If a property is missing clientName, then it will be interpreted as a client for all the properties. For example
ribbon.ReadTimeout = 1000
This will all clients to establish a default ReadTimeout property.
You can also be programmed by setting properties of examples constructed DefaultClientConfigImpl.
If you want to define attributes in different namespace, e.g. "foo"
myclient.foo.ReadTimeout = 1000
feign the configuration of hystrix
Before hystrix be configured first to confirm feign.hystrix.enabled parameter set to true (opened Hystrix fuse protection), otherwise parameter setting close Feign client hystrix, the main configuration is configured to HystrixCommand is in hystrix com.netflix.hystrix.HystrixCommandProperties -core.jar the class file, as configured for certain parameters screenshot
As timeout global configuration:
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds = 5000 // default is 1000ms That 1s
The caller service
The caller transformation services
controller
/ ** Service retry mechanism main presentation ribbon thread sleep, when more than consumer connection timeout configuration, a second reconnection * Does not receive parameters * @return * @throws InterruptedException */ @SuppressWarnings("deprecation") @RequestMapping(value = "/hello1", method = RequestMethod.GET) public String hello() throws InterruptedException { ServiceInstance instance = client.getLocalServiceInstance(); logger.info("/hello1,host:{},service_id:{}",instance.getHost(),instance.getServiceId()); //测试超时 int sleep = new Random().nextInt(3000); logger.info("sleep time:{}",sleep); Thread.sleep(sleep); return "hello spring cloud"; }
Start class service consumers
Package Penalty for com.niugang; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; /** * Feign consumer version * * @Author niugang * */ @SpringBootApplication @EnableDiscoveryClient // scanning declares them feign interface of the client (by @FeignClient) @EnableFeignClients public class the Application { public static void main (String [] args) { SpringApplication.run(Application.class, args); } }
Configuration
Call service interface
Class service degradation
controller
test
Start the registry, start the service category, consumers start
It can be read from the log console print, but the thread sleep more than 2000ms, consumers will sense a second time to reconnect.
When stopped the service provider:
输入:http://localhost:9001/feign-consumer
Implementation of the corresponding service degradation function
输入:http://localhost:9001/feign-consumer1/zhangsan
Implementation of the corresponding service degradation function
Micro-channel public number:
JAVA program ape growth path
Resource sharing, recording program ape growing little by little. Focus on Java, Spring, SpringBoot, SpringCloud, distributed, slightly services.