zoukankan      html  css  js  c++  java
  • spring coud feign

    1. 依赖

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
    </parent>

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    </properties>

    <dependencies>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-feign</artifactId>
    </dependency>


    </dependencies>

    <dependencyManagement>
    <dependencies>
    <dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-dependencies</artifactId>
    <version>Camden.SR7</version>
    <type>pom</type>
    <scope>import</scope>
    </dependency>

    </dependencies>
    </dependencyManagement>
    </project>

    2. 启动类

    @SpringBootApplication
    @EnableEurekaClient
    @EnableFeignClients
    public class FeignApplication {


    public static void main(String[] args) {
    SpringApplication.run(FeignApplication.class, args);
    }

    @Bean
    protected Logger.Level level(){
    return Logger.Level.FULL;
    }
    }

    3. feign

    @FeignClient(name="hello-service",fallback=fallbackHelloFeignClient.class)
    public interface HelloFeignClient {


    @RequestMapping(value="/hello")
    public String hello() throws InterruptedException;

    @Component
    static class fallbackHelloFeignClient implements HelloFeignClient{

    @Override
    public String hello() throws InterruptedException {
    return “error”;
    }

    }
    }

    4. 业务

    @RestController
    public class HelloFeignController {

    @Autowired
    private HelloFeignClient client;


    @GetMapping("/hello")
    public String hello() throws InterruptedException {
    return client.hello();
    }
    }

    5 配置

    server:
    port: 8095
    spring:
    application:
    name: feign-consumer
    eureka:
    client:
    serviceUrl:
    defaultZone: http://ym-eureka-server1:8759/eureka/
    instance:
    preferIpAddress: true
    ribbon:
    ConnectTimeout: 6000
    ReadTimeout: 6000
    hystrix:
    command:
    default:
    execution:
    isolation:
    thread:
    timeoutInMilliseconds: 15000
    feign:
    hystrix:
    enabled: true
    logging:
    level:
    com:
    ym: debug

  • 相关阅读:
    程序员追求的是什么?
    jQuery弹出层始终垂直居中,相对于屏幕,相对于当前窗口
    在VMware上制作一个简单的Linux
    Nginx 反向代理+Varnish 技术
    在做微信分享到朋友圈时,手机扫码报config:invalid signature,分享后后正常的问题,是url问题...
    phpStudy本地环境测试,打开网页很慢的解决办法!
    windows上安装redis并安装php5.6的redis扩展
    Redis 安装
    redis 查看的版本
    who is 规格严格
  • 原文地址:https://www.cnblogs.com/maohuidong/p/9881159.html
Copyright © 2011-2022 走看看