首页 > 其他分享 >springcloud - openFeign的简单配置和使用

springcloud - openFeign的简单配置和使用

时间:2023-07-06 22:34:14浏览次数:39  
标签:openFeign springcloud class 配置 value id payment eureka public

openFeign 第一步:导入依赖

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

第一步:进行配置

 server:
   port: 80
 ​
 eureka:
   client:
     register-with-eureka: false
     service-url:
       defaultZone: http://eureka7001.com:7001/eureka/,http://eureka7002.com:7002/eureka/

第三步:开启注解

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

第四步:对接口进行注解

 @Component
 @FeignClient(value = "CLOUD-PAYMENT-SERVICE")
 public interface PaymentService {
 ​
     @GetMapping(value = "payment/get/{id}")
     CommonResult<Payment> getPaymentById(@PathVariable(value = "id") Long id);
 ​
     @GetMapping(value = "payment/timeout")
     String getPaymentTimeout();
 }

第五步:调用接口

 @RestController
 public class PaymentController {
     @Resource
     private PaymentService paymentService;
 ​
     @GetMapping(value = "consumer/payment/get/{id}")
     public CommonResult<Payment> getPaymentById(@PathVariable("id") Long id) {
         return paymentService.getPaymentById(id);
     }
 ​
     @GetMapping(value = "consumer/payment/timeout")
     public String getPaymentTimeout(){
         return paymentService.getPaymentTimeout();
     }
 }

feign日志增强

   #日志增强
 logging:
   level:
     com.atguigu.springcloud.service.PaymentService: debug

日志增强配置类

 @Configuration
 public class FeignConfig {
     @Bean
     Logger.Level feignLevelInfo(){
         return Logger.Level.FULL; //full表示一个详细日志
     }
 }

feign 超时等待配置 设置指定的时间,等待返回结果,超时报错,默认是1s

 ribbon:
   # 值得是建立连接所用的时间,适用于网络状态正常的情况下,两端连接所用的时间
   ReadTimeout: 5000
   # 指的是建立连接后从服务端读取到可用资源所用的时间
   ConnectTimeout: 5000

标签:openFeign,springcloud,class,配置,value,id,payment,eureka,public
From: https://www.cnblogs.com/huoziqi/p/17533518.html

相关文章

  • springcloud - ribbon简单提点 + 手写轮询算法
    ribbon(依然有人使用,还是很难替换掉)负载均衡+restTemplate实现rpc远程调用新版eureka依赖集成好了ribbon,可以不用重新导入consumer远程调用provider使用到了一个resttemplate类在消费者端的consumer中调用   @Resource   privateRestTemplaterestTemplate;/......
  • 十四、Sentinel配置持久化到Nacos
    Sentinel持久化配置我们首先需要知道:在SentinelDashboard中配置规则之后重启应用就会丢失,所以实际生产环境中需要配置规则的持久化实现,Sentinel提供多种不同的数据源来持久化规则配置,包括file,redis、nacos、zk。Sentinel规则持久化到Nacos将限流规则持久化进Nacos保存,只要刷新......
  • lvs基础配置
    基础配置[root@localhost~]#systemctldisable--nowfirewalldRemovedsymlink/etc/systemd/system/multi-user.target.wants/firewalld.servicRemovedsymlink/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.servic[root@localhost~]#vi/etc/selinux/config......
  • centos7配置阿里云yum源
    #wget下载wget-O/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repo#curl下载(如果yum安装wget失败的话用curl)curl-o/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-7.repo......
  • HBase 组件安装与配置
    HBase组件安装与配置1.1.实验目的完成本实验,您应该能够:掌握HBase安装与配置掌握HBase常用Shell命令1.2.实验要求了解HBase原理熟悉HBase常用Shell命令1.3.实验环境本实验所需之主要资源环境如表1-1所示。表1-1资源环境服务器集群单节点,机器最......
  • Sqoop 组件安装与配置
    1.Sqoop组件安装与配置1.1.实验目的完成本实验,您应该能够:下载和解压Sqoop配置Sqoop环境安装SqoopSqoop模板命令1.2.实验要求熟悉Sqoop环境熟悉Sqoop模板命令1.3.实验环境本实验所需之主要资源环境如表1-1所示。表1-1资源环境服务器集群单节点,机......
  • Flume 组件安装配置
    Flume组件安装配置1.1.实验目的完成本实验,您应该能够:掌握下载和解压Flume掌握Flume组件部署掌握使用Flume发送和接受信息1.2.实验要求了解Flume相关知识熟悉Flume功能应用熟悉Flume组件设置1.3.实验环境本实验所需之主要资源环境如表1-1所示。表1-1......
  • anconda配置tensorflow环境
    一、anconda的安装1.进入Anaconda官网并按照电脑配置选择合适的安装包Anaconda官网:https://www.anaconda.com/点击进入不同的三个版本,分别是windows,mac,linux根据自己的电脑配置下载对应的安装包点击next点击Iagree同意协议默认上面的选择,点击next安装位置可以......
  • 1.Vue3 配置开发-测试环境
    1、根目录新建.env.testing、.env.donline文件2、package.json=》scripts中配置"start":"vue-cli-serviceserve--modetesting","start-o":"vue-cli-serviceserve--modedonline"3、vue.config.jsconstBundleAnalyzerPlugin=require(&......
  • Dynamics CRM字段安全配置文件,实现某个人只能看某条记录的某个字段
    共享安全字段https://blog.csdn.net/bzpfly/article/details/115652147 具体代码写法:https://learn.microsoft.com/zh-cn/power-apps/developer/data-platform/webapi/reference/fieldpermission?view=dataverse-latest  ......