springboot eureka 熔断器


1.继承接口类

2.打开熔断器:

feign.hystrix.enabled=true
package com.ligy.demo.service.impl;

import com.ligy.demo.service.Demo2Service;
import org.springframework.stereotype.Component;

@Component
public class Demo2ServiceImpl implements Demo2Service {
    public String test() {
        return "触发了熔断器。。。";
    }
}
package com.ligy.demo.service;

import com.ligy.demo.service.impl.Demo2ServiceImpl;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;

@FeignClient(value = "eurekademo2", fallback = Demo2ServiceImpl.class)
public interface Demo2Service {

    @RequestMapping("/demo2/test")
    String test();
}
server.port=8087
spring.application.name=eurekademo4
#eureka配置
#eureka.client.registerWithEureka=false
#eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:6868/eureka/
eureka.instance.prefer-ip-address=true
feign.hystrix.enabled=true