zoukankan      html  css  js  c++  java
  • springboot springcloud eureka 熔断器

    1.接口+实现类+注解:

    @FeignClient(value = "eurekademo2", fallback = Demo2ServiceImpl.class)

    2.打开熔断器:

    修改配置文件:application.properties
    feign.hystrix.enabled=true

    package com.ligy.demo.controller;
    
    import com.ligy.demo.service.Demo2Service;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    @RequestMapping("/demo4")
    public class StudentController {
        @Autowired
        Demo2Service demo2Service;
    
        @RequestMapping("/demo2test")
        public String demo2test() {
    
            return demo2Service.test();
        }
    
        @RequestMapping("/test")
        public String test() {
            return "你好,世界demo4";
        }
    }
     
    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


     

    天生我材必有用,千金散尽还复来
  • 相关阅读:
    实现连续测试,要做的事情【译】
    Go语言HTTPServer开发的六种实现
    JSON必知必会【PDF+视频教程】
    给JSONObject添加自定义遍历方法
    利用守护线程隐式关闭线程池
    从错误中学习
    Groovy动态添加方法和属性及Spock单测
    持续测试、持续集成、持续交付、持续部署和DevOps
    有关OAuth 2.0简化模式中步骤D-F的解释
    Spring笔记(五):bean的自动装配
  • 原文地址:https://www.cnblogs.com/ligenyun/p/15782583.html
Copyright © 2011-2022 走看看