万字长文 | 深入理解 OpenFeign 的架构原理

Spring Cloud OpenFeign深入浅出 文章目录1. 简单玩法1.1 一个简单例子1.2 @FeignClient的简单用法2. 高级玩法2.1 configuration配置类2.1.1 Decoder feignDecoder2.1.2 Encoder feignEncoder2.1.3 Retryer feignRetryer2.1.4 Feign.Builder feignBuilder2.1.5 FeignLoggerFact... 阅读详情

上次我们深入讲解了Ribbon 的架构原理,这次我们再来看下 Feign 远程调用的架构原理。

一、理解远程调用

远程调用怎么理解呢?

远程调用 和 本地调用 是相对的,那我们先说本地调用更好理解些,本地调用就是同一个 Service 里面的方法 A 调用方法 B。

那远程调用就是不同 Service 之间的方法调用。Service 级的方法调用,就是我们自己构造请求 URL和请求参数,就可以发起远程调用了。

在服务之间调用的话,我们都是基于 HTTP 协议,一般用到的远程服务框架有 OKHttp3,Netty, HttpURLConnection 等。其调用流程如下:

但是这种虚线方框中的构造请求的过程是很 繁琐 的,有没有更 简便 的方式呢?

Feign 就是来简化我们发起远程调用的代码的,那简化到什么程度呢? 简化成就像调用本地方法那样简单。

比如我的开源项目 PassJava 中的使用 Feign 执行远程调用的代码:

//远程调用拿到该用户的学习时长
R memberStudyTimeList = studyTimeFeignService.getMemberStudyTimeListTest(id);

而 Feign 又是 Spring Cloud 微服务技术栈中非常重要的一个组件,如果让你来设计这个微服务组件,你会怎么来设计呢?

我们需要考虑这几个因素 :

  • 如何使远程调用像本地方法调用简单?

  • Feign 如何找到远程服务的地址的?

  • Feign 是如何进行负载均衡的?

接下来我们围绕这些核心问题来一起看下 Feign 的设计原理。

二、Feign 和 OpenFeign

OpenFeign 组件的前身是 Netflix Feign 项目,它最早是作为 Netflix OSS 项目的一部分,由 Netflix 公司开发。后来 Feign 项目被贡献给了开源组织,于是才有了我们今天使用的 Spring Cloud OpenFeign 组件。

Feign 和 OpenFeign 有很多大同小异之处,不同的是 OpenFeign 支持 MVC 注解。

可以认为 OpenFeign 为 Feign 的增强版 。

简单总结下 OpenFeign 能用来做什么:

  • OpenFeign 是声明式的 HTTP 客户端,让远程调用更简单。

  • 提供了HTTP请求的模板,编写简单的接口和插入注解,就可以定义好HTTP请求的参数、格式、地址等信息

  • 整合了Ribbon(负载均衡组件)和 Hystix(服务熔断组件),不需要显示使用这两个组件

  • Spring Cloud Feign 在 Netflix Feign的基础上扩展了对SpringMVC注解的支持

三、OpenFeign 如何用?

OpenFeign 的使用也很简单,这里还是用我的开源 SpringCloud 项目 PassJava 作为示例。

开源地址: https://github.com/Jackson0714/PassJava-Platform

喜欢的小伙伴来点个 Star 吧,冲 2K Star。

Member 服务远程调用 Study 服务的方法 memberStudyTime(),如下图所示。

第一步 :Member 服务需要定义一个 OpenFeign 接口:

@FeignClient("passjava-study")
public interface StudyTimeFeignService {
    @RequestMapping("study/studytime/member/list/test/{id}")
    public R getMemberStudyTimeListTest(@PathVariable("id") Long id);
}

我们可以看到这个 interface 上添加了注解 @FeignClient ,而且括号里面指定了服务名:passjava-study。 显示声明 这个接口用来远程调用 passjava-study 服务。

第二步 :Member 启动类上添加 @EnableFeignClients 注解开启远程调用服务,且需要开启服务发现。如下所示:

@EnableFeignClients(basePackages = "com.jackson0714.passjava.member.feign")
@EnableDiscoveryClient

第三步 :Study 服务定义一个方法,其方法路径和 Member 服务中的接口 URL 地址一致即可。

URL 地址:"study/studytime/member/list/test/{id}"

@RestController
@RequestMapping("study/studytime")
public class StudyTimeController {
    @RequestMapping("/member/list/test/{id}")
    public R memberStudyTimeTest(@PathVariable("id") Long id) {
       ... 
Spring Boot集成DeepSeek API实战:构建智能问答系统 自然语言处理(NLP)作为人工智能的核心技术,通过让计算机理解和生成人类语言,实现了人机交互的智能化。其原理基于深度学习模型对海量文本数据的学习,能够捕捉语言的语法、语义和上下文信息。这项技术的价值在于大幅降低了人机沟通的门槛,使机器能够执行对话、摘要、翻译等复杂任务。在工程实践中,开发者可以通过调用大模型API,快速为应用注入AI能力,广泛应用于智能客服、内容创作、代码生成等场景。本文以DeepSeek-V3模型为例,详细讲解如何通过Spring Boot框架集成AI API,实现一个完整的智能问答服务, 阅读详情

相关推荐

SpringCloud——OpenFeign详解

目录 一、OpenFeign介绍 1、概念 2、作用 3、架构图 二、OpenFeign案例 1、案例说明 2、搭建Eureka服务端 (1)创建maven工程 (2)导入依赖 (3)配置application.yml (4)创建主启动类 (5)启动Eureka注册中心 3、搭建服务提供者Provider80 (1)创建maven工程 (2)导入依赖 (3)配置application.yml (4)创建启动类 (5)创建controller ......

weixin_50616848的博客 9035

【Spring cloud】OpenFeign详解(超详细)

一、概述 1. OpenFeign是什么? 下面是关于OpenFeign的一段官方介绍: Feign is a declarative web service client. It makes writing web service clients e asier. To use Feign create an interface and annotate it. It has pluggable annotat ion support including Feign annotations and JAX

笑不语的博客 8909

智能音箱麦克风阵列实战:Python实现宽带GSC波束形成(附完整代码)

本文从工程实战角度,详细介绍了如何在智能音箱中利用Python实现宽带GSC波束形成算法。文章深入解析了广义旁瓣消除器(GSC)的核心架构,包括固定波束形成、阻塞矩阵与自适应滤波路径,并提供了完整的仿真代码、关键参数(如LMS步长)调优方法,以及面向嵌入式部署的计算优化与移植考量,旨在帮助开发者构建在真实噪声环境下高效工作的语音增强系统。

opencv7vision的博客 345

python因子数_Python与量化多因子——因子库(下)

1. 前言有点泄气,读者不多,赞同也不多,不过万事开头难。上一篇我分享了因子库的设计,这一篇主要讲实现,加上我的标题叫Python与量化多因子,势必要加点代码在里头,不过旨在抛砖引玉,点到即止,更多的内容需要读者们自己去探索。对了,读者如果自己动手,基础的Pandas,Numpy的操作还是需要会的,网上也有很多教程,大家也可以去看,如果有需要,后面我也可以写篇文章来介绍。2. 因子构成好像现在各家...

weixin_39523625的博客 1234

BunkerWeb 开源 WAF/WAAP 实战:基于 Nginx 的 Web 安全防护部署指南

Web 应用暴露在公网后,SQL 注入、XSS、恶意爬虫与 CC 攻击等威胁接踵而至,仅靠业务代码自建防护很难覆盖层出不穷的攻击变种。WAF(Web 应用防火墙)将安全能力前置到流量入口,成为收敛攻击面的关键手段;而更进一步的 WAAP 则扩展至 API 场景,覆盖防爬、限流与 Bot 识别。BunkerWeb 作为一款基于 Nginx 构建的开源 WAF/WAAP,在保留 Nginx 高性能底座的同时,通过模块化设计集成规则引擎、频率限制、IP 封禁、自动 HTTPS 等能力,并借助 Docker 容器化

weixin_34198881的博客 362

dmx512协议c语言编程,DMX512协议+c程序代码.pdf

DMX512 协议1.协议简介DMX 是Digital MultipleX 的缩写 ,意为多路数字传输。DMX512 控制协议是美国舞台灯光协会(USITT)于1990 年发布的灯光控制器与灯具设备进行数据传输的工业标准 ,全称是 USITT DMX512(1990) ,包括电气特性、数据协议、数据格式等方面的内容。2. 电气特性和物理层2.1. 电气特...

weixin_39928993的博客 2555

基于企业微信客服与GPT-3构建合规微信AI助手:从原理到部署实践

在人工智能与即时通讯融合的浪潮中,自然语言处理(NLP)与API集成成为构建智能对话系统的核心技术。其原理在于通过API网关接收用户输入,调用云端大语言模型进行处理,再将结果返回给用户,实现自动化交互。这项技术的核心价值在于将前沿AI能力无缝嵌入到日常高频应用场景中,极大地提升了客服自动化、智能问答与个性化服务的效率与体验。企业微信作为官方认可的企服平台,其开放的客服API接口为开发者提供了稳定、合规的消息通道,是连接微信生态与外部AI服务的理想桥梁。本文聚焦于如何利用企业微信客服API与OpenAI的GP

weixin_28727943的博客 633

网络设备调试指南:如何用MDIO Clause22/45协议读写Marvell MV88E6390寄存器

本文深入解析了如何通过MDIO Clause 22/45协议对Marvell MV88E6390交换芯片进行寄存器读写调试。文章详细对比了两种协议的本质区别与适用场景,并重点阐述了MV88E6390的直接与间接寻址策略,提供了实战代码示例与关键调试技巧,帮助网络工程师高效解决配置与通信问题。

tequila的博客 524

AUTOSAR TcpIp模块 以太网配置开发2

someip协议之tcpIp协议

汽车电子电气 1090

微信小程序 - 详细实现打开跳转第三方 H5 网页链接,在微信小程序内直接跳转打开第三方网站链接详细教程(支持跳转公众号文章等,直接复制代码即可)

小程序跳转h5,小程序-Taro小程序中打开h5页面链接,...小程序跳转h5链接(web-view)_微信小程序,小程序如何跳转h5页面,小程序跳转到第三方H5网页,微信小程序跳转第三方H5的方法,小程序-实现怎么跳转打开H5网页链接(或跳转至公众号文章,打开第三方网站,放校验文件,怎么配置业务域名,校验文件验证域名,把校验文件放到对面网站,别人的服务器也打不开没权限怎么放呢,勾选不校验合法域名,txt,打不开别人的网页怎么办,真机调试打不开,无法跳转,有什么其他办法不放校验文件吗,后台配置,怎么

🏆 前端领域优质创作者 3万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

上一篇: 要不你给我说说什么是长轮询吧?
下一篇: 2022最新Java面试题含答案,整合面试复盘笔记
JavaMonsterr
博客等级 码龄5年 211粉丝 481原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址