In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the example analysis of Open-Feign integration hystrix downgrade fuse, the article is very detailed, has a certain reference value, interested friends must read it!
1. Server 1. Configuration file
Application.yml
Name of server: port: 9000spring: application: name: my-test2 # service 2, control layer @ RestControllerpublic class ShoppingController {@ RequestMapping ("/ myTestBuy2") public String myTestBuy2 () {/ / used to simulate service timeout try {Thread.sleep (6000);} catch (InterruptedException e) {e.printStackTrace () } return "purchased successfully-time:" + new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss") .format (new Date ()) }} II. Client 1, dependent org.springframework.cloud spring-cloud-starter-openfeign org.springframework.cloud spring-cloud-starter-netflix-hystrix 2, Configuration file server: port: 8000spring: application: name: my-test1 # Service name # allows the service to downgrade the configuration feign: hystrix: enabled: true# Custom ribbon timeout setting is larger than the hystrix-timeoutInMilliseconds timeout ribbon: # refers to the time it takes to read from the server to available resources after establishing a connection. ReadTimeout: 10000 # refers to the time it takes to establish a connection. When the network condition is normal, the time it takes for both ends to connect and the timeout for processing requests is 5 seconds by default. ConnectTimeout: 10000hystrix: command: default: execution: isolation: thread: # feign Integration hystrix Optical Settings Hystrix timeout useless to cooperate with ribbon timeout timeoutInMilliseconds: 5000my-test2: url: http://127.0.0.1:90003, Startup class @ SpringBootApplication@EnableFeignClients// enables open-feign@EnableHystrix// to enable degraded circuit breaker service public class MyTestApplication1 {public static void main (String [] args) {SpringApplication.run (MyTestApplication1.class) Args) 4. Call @ RestControllerpublic class TestController1 {@ Autowired TestService1 testService1; @ RequestMapping ("/ myTestBuy1") public String myTestBuy2 () {return testService1.myTestBuy2 () in the control layer }} 5. Create a class to implement the service FeignClient interface @ Componentpublic class MyHystrix1 implements TestService1 {@ Override public String myTestBuy2 () {return "failed, and the service was fused-- time:" + new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss") .format (new Date ()) }} 6. Configure the FallBack implementation class @ FeignClient (name = "my-test2", url = "${my-test2.url}", fallback = MyHystrix1.class) public interface TestService1 {@ RequestMapping ("/ myTestBuy2") String myTestBuy2 () on the service FeignClient interface.
2. Scenario 2 when the called service stops running
If you only give two seconds, the circuit breaker will be started automatically.
3. Scenario 3 when the calling service times out
Fuse time according to the time set by hystrix, what I set here is 5 seconds.
4. Other
The above is all the contents of this article "the example analysis of Open-Feign integrating hystrix downgrade circuit breaker". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.