首页 > 解决方案 > chaos-monkey 和 spring hystrix 不兼容?

问题描述

我想用 Chaos Monkey 攻击我的微服务,我想用 hystrix 来处理故障。当我单独使用 Chaos Monkey 时,我的应用程序会受到攻击,但是当我使用 hystrix 时,Chaos Monkey 不会进行任何攻击。

为什么我不能同时使用?是版本问题吗?

@SpringBootApplication
@EnableCircuitBreaker
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

@RestController
public class Controller {

    @Autowired
    private Service service;

    @RequestMapping("/list")
    public List<String> getList() {
        return service.getList();
    }
}

@Service
public class Service {

    @Autowired
    private Repo repo;

    @HystrixCommand(fallbackMethod = "reliable")
    public List<String> getList() {
        return repo.getList();
    }

    public List<String> reliable() {
        return Arrays.asList("ONE", "TWO", "THREE");
    }
}

@Repository
public class Repo {
    public List<String> getList() {
        return Arrays.asList("Java", "PHP", "C++");
    }
}

Application.properties
spring.profiles.active=chaos-monkey
chaos.monkey.enabled=true
chaos.monkey.watcher.controller=false
chaos.monkey.watcher.restController=false
chaos.monkey.watcher.service=true
chaos.monkey.watcher.repository=false
chaos.monkey.assaults.latencyActive=false
chaos.monkey.assaults.exceptions-active=true

标签: javaspringspring-boothystrixspring-boot-chaos-monkey

解决方案


推荐阅读