当前位置:网站首页>Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
2022-07-06 13:08:00 【Geometer】
First, let's introduce the concept of service registration
Actually DNS It is a service registration , In microservices . The application instance obtains the information of the service instance through the registry , Use this information to request the parameters they provide
There are ten instances of a service ,client How to know which one to visit ?
Service registration is needed to help us
First deploy a service center locally Nacos:
Start good nacos On the one hand, it can monitor API, On the one hand, there is a console
First, deploy a service End
You can see nacos You can find that the service has been registered to the service center
Now deploy Consumer
consumer It can be used REST Template and Feign Client To write
Briefly introduce these two gadgets , They are all based on http Protocol to communicate
rest template It needs to be assembled every time url, It is relatively simple to use ,RestTemplate In splicing url When , You can specify ip Address + Port number , You can directly request the interface without going through the service registry ; You can also specify a service name , Request to go to the service registry first ( Such as nacos) Get the corresponding service ip Address + Port number , And then pass by HTTP Forward the request to the corresponding service interface ( need @LoadBalanced)
Feign The underlying implementation of is dynamic agent , Its use is realized through annotations , It is also mapped through the service center
About feigin Use :
1. stay consumer add to @@EnableFeignClients
2. stay consumer add to Feign The interface of ( Use @FeignClient(value = “service-provider”), among value It refers to the services of producers ),producer Is the service that implements this interface
3. stay producer Created in controller Interface , Realization 2 The specific logic of the interface in
4. stay consumer Call in the
边栏推荐
- Pride-pppar source code analysis
- 十分鐘徹底掌握緩存擊穿、緩存穿透、緩存雪崩
- Realization of the code for calculating the mean square error of GPS Height Fitting
- 记录:Navicat Premium初次无法连接数据库MySQL之解决
- [algorithm] sword finger offer2 golang interview question 7: 3 numbers with 0 in the array
- 4.30 dynamic memory allocation notes
- TYUT太原理工大学2022软工导论考试题型大纲
- 【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
- Employment of cashier [differential constraint]
- Record: I accidentally wrote a recursion next time
猜你喜欢
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
[algorithm] sword finger offer2 golang interview question 5: maximum product of word length
One article to get UDP and TCP high-frequency interview questions!
3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法
【无标题】
[算法] 剑指offer2 golang 面试题12:左右两边子数组的和相等
121 distributed interview questions and answers
2年经验总结,告诉你如何做好项目管理
[算法] 剑指offer2 golang 面试题10:和为k的子数组
Answer to "software testing" exercise: Chapter 1
随机推荐
[algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
4.30 dynamic memory allocation notes
[算法] 剑指offer2 golang 面试题10:和为k的子数组
平衡二叉树详解 通俗易懂
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
Fairygui bar subfamily (scroll bar, slider, progress bar)
Detailed explanation of balanced binary tree is easy to understand
基本Dos命令
[algorithm] sword finger offer2 golang interview question 1: integer division
165. Compare version number - string
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
121 distributed interview questions and answers
Implementation of Excel import and export functions
[算法] 劍指offer2 golang 面試題2:二進制加法
Iterable、Collection、List 的常见方法签名以及含义
[rtklib 2.4.3 B34] version update introduction I
Sharing ideas of on-chip transplantation based on rtklib source code
On March 15, the official version of go 1.18 was released to learn about the latest features and usage
记录:newInstance()过时的代替方法
[算法] 剑指offer2 golang 面试题6:排序数组中的两个数字之和