当前位置:网站首页>Use of hystrix
Use of hystrix
2022-07-25 12:29:00 【dengjili】
Hystrix Project use
To configure pom.xml rely on
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
To configure RestTemplate object
@Configuration
public class RestTemplateConfiguration {
@Bean
public RestTemplate create() {
return new RestTemplate();
}
}
Add test class
@RestController
public class HystrixController {
@Autowired
private RestTemplate restTemplate;
@HystrixCommand(fallbackMethod = "failCallHello")
@GetMapping("/hello")
public String callHello() {
String result = restTemplate.getForObject("http://192.168.1.55:8081/hello", String.class);
return result;
}
public String failCallHello() {
return "Fail";
}
@HystrixCommand(fallbackMethod = "failCallHello", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000") })
@GetMapping("/hello2")
public String callHello2() {
String result = "Ok";
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
return result;
}
}
- /hello The test program is abnormal
- /hello2 Test timeout exception
Activate Hystrix, Start the class to add comments @EnableHystrix
@EnableHystrix
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Get ready
start-up Eureka service , And register two applications as test cluster machines , As shown in the figure ; Test interface /hello
Feign Project use
Then add the configuration pom.xml rely on
<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>
encapsulation Feign Interface ,eureka-provider-app To register to Eureka Service name in
@FeignClient(value = "eureka-provider-app", fallback = TestClientFailBack.class)
public interface TestClient {
@GetMapping("/hello")
String hello();
}
TestClientFailBack Failure handling strategy
@Component
public class TestClientFailBack implements TestClient{
@Override
public String hello() {
return "FAIL_fail";
}
}
Add test class
@RestController
public class TestController {
@Autowired
private TestClient client;
@GetMapping("/test")
public String test() {
String result = client.hello();
return result;
}
}
Activate Feign To configure
@EnableFeignClients(basePackageClasses = {
TestClient.class})
@EnableHystrix
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
The configuration file application.properties add to Eureka Registration configuration , start-up feign And hystrix Integrate
eureka.client.serviceUrl.defaultZone=http://192.168.1.55:8761/eureka/
feign.hystrix.enabled=true```
Add test class
```java
@RestController
public class TestController {
@Autowired
private TestClient client;
@GetMapping("/test")
public String test() {
String result = client.hello();
return result;
}
}
test , Successful test

Stop the app , test 
边栏推荐
- 面试官:“同学,你做过真实落地项目吗?”
- 【二】栅格数据显示拉伸色带(以DEM数据为例)
- Hystrix使用
- Visualize the training process using tensorboard
- Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network
- Implementation of recommendation system collaborative filtering in spark
- If you want to do a good job in software testing, you can first understand ast, SCA and penetration testing
- 【8】 Clever use of color finder
- Pytorch main module
- Brpc source code analysis (IV) -- bthread mechanism
猜你喜欢

Hystrix使用

2022.07.24(LC_6126_设计食物评分系统)

PyTorch可视化

技术管理杂谈

客户端开放下载, 欢迎尝鲜

防范SYN洪泛攻击的方法 -- SYN cookie

Musk's "eternal soul": half hype, half flicker

Fiddler packet capturing app

Microsoft azure and Analysys jointly released the report "Enterprise Cloud native platform driven digital transformation"

Implement anti-theft chain through referer request header
随机推荐
启牛开的证券账户安全吗?是怎么开账户的
numpy初识
mysql实现一张表数据插入另一张表
Pytorch main module
R language ggpubr package ggarrange function combines multiple images and annotates_ Figure function adds annotation, annotation and annotation information for the combined image, adds image labels fo
PyTorch项目实战—FashionMNIST时装分类
pytorch环境配置及基础知识
NLP knowledge - pytorch, back propagation, some small pieces of notes for predictive tasks
Add a little surprise to life and be a prototype designer of creative life -- sharing with X contestants in the programming challenge
软件测试面试题目:请你列举几个物品的测试方法怎么说?
基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
【3】 DEM mountain shadow effect
Jenkins configuration pipeline
Jenkins配置流水线
Fiddler抓包APP
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the dot strip chart, set the palette parameter to configure the color of data points at different levels,
Zuul gateway use
Those young people who left Netease
PyTorch的生态简介
Eureka usage record