当前位置:网站首页>阿里云微服务(一)服务注册中心Nacos以及REST Template和Feign Client
阿里云微服务(一)服务注册中心Nacos以及REST Template和Feign Client
2022-07-06 09:19:00 【几何学家】
首先来介绍下服务注册的概念
其实DNS就是一个服务注册,在微服务中。应用实例通过注册中心获取到服务实例的信息,通过这些信息去请求他们提供的参数
一个服务有十个实例,client怎么知道访问哪一个呢?
这中间就需要服务注册来帮助我们
先在本地部署一个服务中心Nacos:
启动好的nacos一方面可以监听API,一方面有一个控制台
首先部署一个service端

可以看到nacos上已经能够发现该服务已经注册到服务中心上去了

下面部署Consumer
consumer可以用REST Template和Feign Client编写
简单介绍一些这两个小玩意,他们都是基于http协议进行通讯
rest template需要每次都拼装url,使用相对来说较为简单,RestTemplate在拼接url的时候,可以直接指定ip地址+端口号,不需要经过服务注册中心就可以直接请求接口;也可以指定服务名,请求先到服务注册中心(如nacos)获取对应服务的ip地址+端口号,然后经过HTTP转发请求到对应的服务接口(需要@LoadBalanced)
Feign的底层实现是动态代理,其使用是通过注解来实现,也是通过服务中心进行映射
关于feigin的使用:
1.在consumer添加@@EnableFeignClients
2.在 consumer添加Feign的接口(使用@FeignClient(value = “service-provider”),其中value指明的是生产者的服务),producer就是实现该接口的服务
3.在producer中创建controller接口,实现2中的接口的具体逻辑
4.在consumer中进行调用
边栏推荐
- [algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K
- [algorithm] sword finger offer2 golang interview question 5: maximum product of word length
- [Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
- Realization of the code for calculating the mean square error of GPS Height Fitting
- [算法] 剑指offer2 golang 面试题4:只出现一次的数字
- Knowledge system of digital IT practitioners | software development methods -- agile
- Error: symbol not found
- KF UD decomposition pseudo code implementation advanced [2]
- 最短Hamilton路径 (状压DP)
- [algorithm] sword finger offer2 golang interview question 9: subarray with product less than k
猜你喜欢
![Fundamentals of UD decomposition of KF UD decomposition [1]](/img/e9/564e0163c3756c0ba886913f1cfaef.jpg)
Fundamentals of UD decomposition of KF UD decomposition [1]

Fgui project packaging and Publishing & importing unity & the way to display the UI

Combination of fairygui check box and progress bar

FairyGUI簡單背包的制作

XV Function definition and call

《软件测试》习题答案:第一章

Edit distance (multi-source BFS)

RTKLIB: demo5 b34f. 1 vs b33

地球围绕太阳转

染色法判定二分图
随机推荐
Excel导入,导出功能实现
KF UD分解之伪代码实现进阶篇【2】
Fairygui character status Popup
面试必备:聊聊分布式锁的多种实现!
It has been solved by personal practice: MySQL row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT
Affichage du changement de valeur du Buff de gain de l'interface graphique de défaillance
KF UD分解之UD分解基础篇【1】
What are the functions and features of helm or terrain
MySQL shutdown is slow
Fabrication d'un sac à dos simple fairygui
Agile development helps me
What are the advantages of using SQL in Excel VBA
How to reduce the shutdown time of InnoDB database?
Comparative analysis of the execution efficiency of MySQL 5.7 statistical table records
Edit distance (multi-source BFS)
【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
闇の連鎖(LCA+树上差分)
121道分布式面试题和答案
[算法] 剑指offer2 golang 面试题10:和为k的子数组
Code example of MATLAB reading GNSS observation value o file