zoukankan      html  css  js  c++  java
  • openFeign的使用

    作用

      类似ribbon提供客户端的负载均衡

    1:pom

     <!---  eureka-client  -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            </dependency>
    
            <!-- openfeign  -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-openfeign</artifactId>
            </dependency>

    2:yml

    server:
      port: 80 #服务端口号
    
    spring:
      application:
        name: cloud-order-service
    
    eureka:
      client:
        fetch-registry: true
        register-with-eureka: true
        service-url:
          defaultZone: http://eureka7002.com:7002/eureka/,http://eureka7001.com:7001/eureka/

    3:seivice接口

    @Component
    @FeignClient(value = "CLOUD-PAYMENT-SERVICE")
    public interface PaymentService {
    
        @GetMapping(value = "/payment/get/{id}")
        BaseResult findById(@PathVariable("id") Integer id);
    } 
      @FeignClient  //#标记该类为openFeign的接口
      (value = "CLOUD-PAYMENT-SERVICE")  //#eureka服务的提供方

    4:启动类

    @SpringBootApplication
    @EnableFeignClients
    public class FeignOrderMain80 {
    
        public static void main(String[] args) {
            SpringApplication.run(FeignOrderMain80.class);
        }
    }

      @EnableFeignClients  #开启使用openFeign

  • 相关阅读:
    poj3016
    BZOJ2560 串珠子
    HAOI 2009 逆序对数列
    BJOI2012 最多的方案
    ZJOI2008 生日聚会
    ZJOI2008 骑士
    SCOI2003 严格N元树
    SDOI2010 地精部落
    USACO Section 3.2 Stringsobits
    JLOI2013 卡牌游戏
  • 原文地址:https://www.cnblogs.com/draymond/p/12726440.html
Copyright © 2011-2022 走看看