openfeign 负载均衡调用服务

https://github.com/spring-cloud/spring-cloud-openfeign

openFeign, fegin 👆

    • open fegin
    • openFegin使用
    • 日志打印配置类

open fegin

  1. Feign是一个声明式的web服务客户端,让编写web服务客户端变得非常容易,只需创建一个接口并在接口上添加注解即可。
  2. feign简化了spring cloud ribbon, 自身集成了ribbon, 可负载均衡。
  3. 面向接口服务调用.
  4. openFegin支持springmvc 注解,取代fegin,fegin out…

openFegin使用

pom

    <!-- open-feign demo, based on client~ and get a ribbon~ --><!--https://github.com/spring-cloud/spring-cloud-openfeign--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency>

yaml
超时控制和日志记录

server:port: 80# 未暴露服务名,属于客户端eureka:client:register-with-eureka: falseservice-url:defaultZone: http://eureka7001.com:7001/eureka,http://eureka7002.com:7002/eureka# 设置feign客户端超时时间(OpenFeign支持默认支持ribbon)
ribbon:# 建立连接所有的时间,适用于网络正常的情况下,两端连接所有的时间ReadTimeout: 5000# 指的是建立连接后从服务器读取到可用资源的时间ConnectTimeout: 5000# feign 调用远程服务日志记录
logging:# 需要开启日志的客户端level:top.bitqian.springcloud.service.PaymentFeignService: debug

主启动

@EnableFeignClients

服务接口, 调用服务提供者

package top.bitqian.springcloud.service;import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import top.bitqian.springcloud.entity.CommonResult;
import top.bitqian.springcloud.entity.Payment;/*** 业务层 feign~* 需要feignClient 和 服务提供者的接口* restTemplate + ribbon 是一套~* @author echo lovely* @date 2020/12/8 22:02*/// 被调用的微服务名称
@FeignClient(value = "CLOUD-PAYMENT-SERVICE")
@Component
public interface PaymentFeignService {@GetMapping("/payment/get/{id}")CommonResult<Payment> getPaymentById(@PathVariable("id") Long id);// 模拟某个业务进行,调用feign接口@GetMapping("/payment/feign/timeout")String paymentFeignTimeout();
}

日志打印配置类

package top.bitqian.springcloud.config;import feign.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** 记录调用服务端的日志* 通过调整日志级别,从而了解Feign中的http请求细节* 对feign接口调用情况,进行监控和输出~* None     默认的不显示任何日志* BASIC    仅记录请求方法,url,响应状态码,及执行时间* HEADERS  basic 请求响应的头信息* FULL     headers 请求响应的正文,数据* @author echo lovely* @date 2020/12/9 22:26*/@Configuration
public class FeignConfig {// 响应,请求信息~@BeanLogger.Level feignLoggerLevel() {return Logger.Level.FULL;}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/420449.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MVC中使用ajax传递json数组

解决方法 去www.json.org下载JSON2.js再调用JSON.stringify(JSONData)将JSON对象转化为JSON串。var people [{ "UserName": "t1", "PassWord": "111111", "Sex": "男" }, { "UserName": "t2"…

hystrix断路器引发的相关概念

1 分布式系统面临的问题 服务雪崩 多个微服务之间调用的时候&#xff0c;假设微服务A调用微服务B和微服务C,微服务B和微服务C又调用其它的微服务,这就是所谓的"扇出”&#xff0c;如果扇出的链路上某个微服务的调用响应时间过长或者不可用&#xff0c;对微服务A的调用就会…

ABAP 弹出框自建内容POPUP

可以自己设计内容&#xff0c;仅供参考。转载于:https://www.cnblogs.com/matinal/p/4135269.html

前端学习(1287):node.js的组成

var first hello nodejs; console.log(first);function fn() {console.log("fn函数被调用了"); }fn();for (var i 0; i < 5; i) {console.log(i); }if (true) {console.log(123); } 运行结果

gateway路由网关,zuul的替代品

zuul1 low, zuul2 还没长大呢&#xff0c;不敢用。 gateway 基于netty, spring flux, reactor 异步非阻塞, 快呀。 与spring良好整合, spring社区的呢。官方推荐。https://spring.io/projects/spring-cloud-gateway https://cloud.spring.io/spring-cloud-static/spring-cloud-…

ASP.NET MVC 5 入门教程 (3) 路由route

文章来源&#xff1a; Slark.NET-博客园 http://www.cnblogs.com/slark/p/mvc-5-get-started-route.html 上一节&#xff1a;ASP.NET MVC 5 入门教程 (2) 控制器Controller 下一节&#xff1a;ASP.NET MVC 5 入门教程 (4) View和ViewBag 源码下载&#xff1a;点我下载 上一节我…

spring cloud config 配置中心

/(ㄒoㄒ)/~~ 还有好多要学鴨 cloud config分布式面临的系统配置问题&#xff0c;如何解决分为服务端配置与客户端配置客户端不能自动更新git上的配置分布式面临的系统配置问题&#xff0c;如何解决 1. 分布式系统面临的配置问题 微服务意味着要将单体应用中的业务拆分成一个个…

前端学习(1289):nodejs模块化的开发规范

demo02.js const add (n1, n2) > n1 n2exports.add add; demo03.js const a require(./demo02.js); console.log(a); 运行结果

spring cloud bus消息总线

解决的痛点: 当git仓库的配置更新后&#xff0c; cloud config 客户端不能获取到配置信息的问题, 需要手动发送请求&#xff0c;刷新配置。 可以参照 spring cloud config cloud busbus消息总线使用rabbitMQ推送消息原理架构实现使用curl命令刷新客户端的配置bus bus配合conf…

前端学习(1290):nodejs模块化的开发导出另一种方式

demo04.js const greeting _name > hello ${_name};module.exports.greeting greeting; demo05.js const a require(./demo04.js); console.log(a); console.log(a.greeting(geyao)); 运行结果 demo04.js const greeting _name > hello ${_name}; const x 100;…

c++ 匿名函数

#include<iostream> #include <cstdlib> using namespace std;int main() {//为了在以后便于区分&#xff0c;我这段main()代码叫做main1autofunc [] { printf("%d\n",1989); };func();system("pause");return 0; } 转载于:https://www.cnblo…

SpringCloud Stream消息驱动

为啥有这个技术&#xff1f;&#xff1f;&#xff1f; 1. 这个stream是操作消息队列的&#xff0c;简化&#xff0c;学习消息队列的成本降低。 2. 可操作rabbitMQ兔子message queue&#xff0c;kafaka&#xff0c;可理解为jdbc可操作oracle, mysql.. 3. spring家的技术学就完了…

前端学习(1291):nodejs的系统模块文件读取操作

//通过模块对模块进行引入 const fs require(fs); //读取文件 fs.readFile(./demo01.js, utf8, (err, doc) > {console.log(err);console.log(doc); }) 运行结果

解决MySQL忘记root密码

网上有很多关于忘记MySQL root密码的一些文章&#xff0c;里面都有写怎么去解决&#xff0c;但有时觉得写得太恶心&#xff0c;要么一字不漏的抄别人的&#xff0c;要么就说得不清不楚&#xff0c;好了&#xff0c;不吐槽了&#xff0c;以下是解决的整个过程。 首先我们要知道忘…

SpringCloud Sleuth分布式请求链路追踪

概念 1. 为什么需要链路追踪&#xff1f; 在微服务框架中&#xff0c;一个由客户端发起的请求在后端系统中 会经过多个不同的的服务节点调用来协同产生最后的请求结果, 每一个前段请求都会形成一复杂的分布式服务调用链路, 链路中的任何一环出现高延时或错误都会引起整个请求最…

前端学习(1292):文件写入操作

const fs require(fs);fs.writeFile(./demo.txt, 即将要写入的内容, err > {if (err ! null) {console.log(err);return;}console.log(文件内容写入成功); }) 运行结果

Android中如何下载文件并显示下载进度

原文地址&#xff1a;http://jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/1125/2057.html 这里主要讨论三种方式&#xff1a;AsyncTask、Service和使用DownloadManager。 一、使用AsyncTask并在进度对话框中显示下载进度 这种方式的优势是你可以在后台执行下载任务的同时…

前端学习(1293):系统模块path路径操作

//导入path模块 const path require(path); //路径拼接 const finaPath path.join(public, uploads, avater); console.log(finaPath); 运行结果

nacos作为服务注册中心

nacosnacos简介nacos 作为服务注册中心demo基于Nacos的服务提供者基于Nacos的服务消费者nacos切换ap和cp 模式nacos简介 为什么叫nacos 前四个字母分别为Naming和Configuration的前两个字母&#xff0c;最后的s为Service。是什么 一个更易于构建云原生应用的动态服务发现&am…