当前位置:网站首页>阿里云微服务(一)服务注册中心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中进行调用
边栏推荐
- 最短Hamilton路径 (状压DP)
- 地球围绕太阳转
- 雇佣收银员【差分约束】
- 【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
- Devops' future: six trends in 2022 and beyond
- 堆排序【手写小根堆】
- Fgui project packaging and Publishing & importing unity & the way to display the UI
- Fairygui joystick
- Knowledge system of digital IT practitioners | software development methods -- agile
- [算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和
猜你喜欢
![[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
![[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity](/img/9d/7284c1399964d3fb48886f12e4941c.jpg)
[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity
![Fundamentals of UD decomposition of KF UD decomposition [1]](/img/e9/564e0163c3756c0ba886913f1cfaef.jpg)
Fundamentals of UD decomposition of KF UD decomposition [1]

FairyGUI条子家族(滚动条,滑动条,进度条)

国企秋招经验总结

FairyGUI按钮动效的混用

Fairygui bar subfamily (scroll bar, slider, progress bar)

面试必备:聊聊分布式锁的多种实现!

The port is occupied because the service is not shut down normally

How to ensure data consistency between MySQL and redis?
随机推荐
Meanings and differences of PV, UV, IP, VV, CV
Fairygui gain buff value change display
[algorithme] swordfinger offer2 golang question d'entrevue 2: addition binaire
How to improve the deletion speed of sequential class containers?
KF UD分解之UD分解基础篇【1】
[Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K
Rt-ppp test using rtknavi
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
Role movement in the first person perspective
NovAtel 板卡OEM617D配置步骤记录
Chromatic judgement bipartite graph
3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法
Excel导入,导出功能实现
Devops' future: six trends in 2022 and beyond
Special palindromes of daily practice of Blue Bridge Cup
[GNSS] robust estimation (robust estimation) principle and program implementation
[算法] 剑指offer2 golang 面试题4:只出现一次的数字
121 distributed interview questions and answers
Mixed use of fairygui button dynamics