zoukankan      html  css  js  c++  java
  • 断路器Feign

    Feign是自带断路器,需要在配置文件中开启断路器

    改造消费者项目(FeignDemo)

    1、在application.yml配置文件中开启断路器

    eureka:
      client:
        service-url:
          defaultZone: http://127.0.0.1:9000/eureka/
    server:
      port: 9004
    spring:
      application:
        name: cppdy-feign
    feign:
      hystrix:
        enabled: true

    2、创建HelloServiceImpl实现类

    package com.cppdy.service.impl;
    
    import org.springframework.stereotype.Component;
    
    import com.cppdy.service.HelloService;
    
    @Component
    public class HelloServiceImpl implements HelloService {
    
        @Override
        public String hello(String name) {
    
            return "Sorry,Server Error:" + name;
        }
    
    }

    3、在HelloService接口中设置断路器回调实现类

    package com.cppdy.service;
    
    import org.springframework.cloud.netflix.feign.FeignClient;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    
    import com.cppdy.service.impl.HelloServiceImpl;
    
    @FeignClient(value = "cppdy-hello", fallback = HelloServiceImpl.class)
    public interface HelloService {
    
        @RequestMapping("hello")
        String hello(@RequestParam("name") String name);
    }

     4、先启动EurekaDemo(注册中心项目),再启动FeignDemo(消费者项目)端口号设置为9004,访问http://localhost:9004/hello,会调用断路器设置的回调实现类中的方法

  • 相关阅读:
    XSS
    XSS练习小游戏
    CTF中常见的编码
    BugkuCTF
    A、B、C、D和E类IP地址
    JDK和JRE的区别及配置
    SQL注入漏洞测试(HTTP头注入)
    MS17-010远程溢出漏洞(CVE-2017-0143)拿权限
    SQL注入——布尔型盲注注入攻击——手工注入篇——SQL手工注入漏洞测试(MySQL数据库)
    mysql增删改查
  • 原文地址:https://www.cnblogs.com/jiefu/p/10056266.html
Copyright © 2011-2022 走看看