当前位置:网站首页>阿里云微服务(一)服务注册中心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中进行调用
边栏推荐
- PRIDE-PPPAR源码解析
- Compile GDAL source code with nmake (win10, vs2022)
- KF UD分解之UD分解基础篇【1】
- The master of double non planning left the real estate company and became a programmer with an annual salary of 25W. There are too many life choices at the age of 25
- Chromatic judgement bipartite graph
- On March 15, the official version of go 1.18 was released to learn about the latest features and usage
- How to reduce the shutdown time of InnoDB database?
- 如何保障 MySQL 和 Redis 的数据一致性?
- wsl常用命令
- [GNSS] robust estimation (robust estimation) principle and program implementation
猜你喜欢

使用rtknavi进行RT-PPP测试

Fabrication d'un sac à dos simple fairygui
![[algorithm] sword finger offer2 golang interview question 6: sum of two numbers in the sorting array](/img/d5/4bda133498f71ae9fd7a64c6cba8f0.png)
[algorithm] sword finger offer2 golang interview question 6: sum of two numbers in the sorting array
![[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等](/img/11/ee0628a68542236fc641966579a31a.png)
[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等
![[algorithm] sword finger offer2 golang interview question 10: subarray with sum K](/img/63/7422489d09a64ec9f0e79378761bf1.png)
[algorithm] sword finger offer2 golang interview question 10: subarray with sum K

Liste des boucles de l'interface graphique de défaillance

RTKLIB: demo5 b34f. 1 vs b33

Excel导入,导出功能实现

Fabrication of fairygui simple Backpack

染色法判定二分图
随机推荐
Prove the time complexity of heap sorting
几道高频的JVM面试题
KF UD分解之伪代码实现进阶篇【2】
《软件测试》习题答案:第一章
编辑距离(多源BFS)
The master of double non planning left the real estate company and became a programmer with an annual salary of 25W. There are too many life choices at the age of 25
[Yu Yue education] guide business reference materials of Wuxi Vocational and Technical College of Commerce
Meanings and differences of PV, UV, IP, VV, CV
错误:排序与角标越界
[rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
面试必备:聊聊分布式锁的多种实现!
[算法] 剑指offer2 golang 面试题9:乘积小于k的子数组
架构师怎样绘制系统架构蓝图?
isEmpty 和 isBlank 的用法区别
Record: Navicat premium can't connect to MySQL for the first time
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
Role movement in the first person perspective
Affichage du changement de valeur du Buff de gain de l'interface graphique de défaillance
Database table splitting strategy
记录:newInstance()过时的代替方法