GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — menu · leehl/PassJava-Learning@48855fb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • docs
    • 13.SpringCloud架构剖析
      • 03.Feign远程调用
        • 01.Feign远程调用基本原理和使用.md
      • 07.Nacos配置注册中心
        • 01.使用Nacos作为注册中心.md
        • 02.Nacos架构原理之注册中心.md
        • 02.使用Nacos作为配置中心.md
        • 03.Nacos架构原理之配置中心.md
    • 16.消息队列
      • 01.RocketMQ.md
    • _sidebar.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎docs/13.SpringCloud架构剖析/03.Feign远程调用/01.Feign远程调用基本原理和使用.md‎

Copy file name to clipboardExpand all lines: docs/13.SpringCloud架构剖析/03.Feign远程调用/01.Feign远程调用基本原理和使用.md
+63-1Lines changed: 63 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,75 @@ OpenFeign 是 Springcloud 在 Feign的基础上支持了 SpringMVC 的注解,
2828

2929
源码地址:https://github.com/openfeign/feign
3030

31-
未完待续。
31+
## 代码示例
3232

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

35+
> 开源地址: https://github.com/Jackson0714/PassJava-Platform
36+
>
37+
> 喜欢的小伙伴来点个 Star 吧,冲 2K Star。
3438
39+
Member 服务远程调用 Study 服务的方法 memberStudyTime(),如下图所示。
3540

41+
![](http://cdn.jayh.club/uPic/image-20220113225405776dmM2KJpRRIUT.png)
3642

43+
**第一步**:Member 服务需要定义一个 OpenFeign 接口:
3744

45+
```java
46+
@FeignClient("passjava-study")
47+
public interface StudyTimeFeignService {
48+
@RequestMapping("study/studytime/member/list/test/{id}")
49+
public R getMemberStudyTimeListTest(@PathVariable("id") Long id);
50+
}
51+
```
52+
53+
我们可以看到这个 interface 上添加了注解`@FeignClient`,而且括号里面指定了服务名:passjava-study。**显示声明**这个接口用来远程调用 `passjava-study`服务。
54+
55+
**第二步**:Member 启动类上添加 `@EnableFeignClients`注解开启远程调用服务,且需要开启服务发现。如下所示:
56+
57+
```java
58+
@EnableFeignClients(basePackages = "com.jackson0714.passjava.member.feign")
59+
@EnableDiscoveryClient
60+
```
61+
62+
**第三步**:Study 服务定义一个方法,其方法路径和 Member 服务中的接口 URL 地址一致即可。
63+
64+
URL 地址:"study/studytime/member/list/test/{id}"
65+
66+
```java
67+
@RestController
68+
@RequestMapping("study/studytime")
69+
public class StudyTimeController {
70+
@RequestMapping("/member/list/test/{id}")
71+
public R memberStudyTimeTest(@PathVariable("id") Long id) {
72+
...
73+
}
74+
}
75+
```
76+
77+
**第四步**:Member 服务的 POM 文件中引入 OpenFeign 组件。
78+
79+
```java
80+
<dependency>
81+
<groupId>org.springframework.cloud</groupId>
82+
<artifactId>spring-cloud-starter-openfeign</artifactId>
83+
</dependency>
84+
```
85+
86+
**第五步**:引入 studyTimeFeignService,Member 服务远程调用 Study 服务即可。
87+
88+
```java
89+
Autowired
90+
private StudyTimeFeignService studyTimeFeignService;
91+
92+
studyTimeFeignService.getMemberStudyTimeListTest(id);
93+
```
94+
95+
通过上面的示例,我们知道,加了 @FeignClient 注解的接口后,我们就可以调用它定义的接口,然后就可以调用到远程服务了。
96+
97+
> 这里你是否有疑问:为什么接口都没有实现,就可以调用了?
98+
99+
OpenFeign 使用起来倒是简单,但是里面的原理可没有那么简单,OpenFeign 帮我们做了很多事情,接下来我们来看下 OpenFeign 的架构原理。
38100

39101
## QA
40102

Collapse file

‎docs/13.SpringCloud架构剖析/07.Nacos配置注册中心/01.使用Nacos作为注册中心.md‎

Copy file name to clipboardExpand all lines: docs/13.SpringCloud架构剖析/07.Nacos配置注册中心/01.使用Nacos作为注册中心.md
+2Lines changed: 2 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# 使用 Nacos 作为注册中心和配置中心
2+
13
大家好,我是悟空呀,上次我们讲解了 [OpenFeign 的架构原理](https://mp.weixin.qq.com/s/7EJTSw5WGE5bYbo00nZ4jA),这次我们要来进入 Nacos 帝国了,Nacos 作为服务注册中心、配置中心,已经非常成熟了,业界的标杆,在讲解 Nacos 的架构原理之前,我先给大家来一篇开胃菜:讲解 Nacos 如何使用,涉及到如下两个话题:
24

35
- 用 Nacos 作为注册中心。
Collapse file

‎docs/13.SpringCloud架构剖析/07.Nacos配置注册中心/02.Nacos架构原理之注册中心.md‎

Copy file name to clipboard
+27Lines changed: 27 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 深入理解 Nacos 的架构原理之注册中心
2+
3+
大家好,我是悟空呀,上次我们讲解了 [Nacos 的配置和使用](https://mp.weixin.qq.com/s/7EJTSw5WGE5bYbo00nZ4jA),Nacos 为服务注册中心、配置中心,对开发和运维同学是非常友好的。为什么 Nacos 这么优秀呢?这次我们就要来探索下 Nacos 的内核原理了。
4+
5+
首先我们心中对 Nacos 一定有些许疑问:
6+
7+
-
8+
-
9+
10+
Nacos
11+
12+
13+
14+
加上希望可以和 Raft 算法库的支持团队 随时沟通交流,因此选择了 JRaft,选择 JRaft 也是因为 JRaft 支持多 RaftGroup,为 Nacos 后 面的多数据分片带来了可能。
15+
16+
Distro 协议是阿里巴巴自研的一个最终一致性协议。Distro 算法是集 Gossip 以及 Eureka 协议的优点并加以优化而出 来的,对于原生的 Gossip,由于随机选取发送消息的节点,也就不可避免的存在消息重复发送给同 一节点的情况,增加了网络的传输的压力,也给消息节点带来额外的处理负载,而 Distro 算法引入 了权威 Server 的概念,每个节点负责一部分数据以及将自己的数据同步给其他节点,有效的降低 了消息冗余的问题。
17+
18+
19+
20+
Nacos 的保证了 AP 和 CP,
21+
22+
Nacos 注册中心采用 AP(最终一致性),为什么不采用强一致性?
23+
24+
最终一致共识算法的话,更多保障服务的可用性,并且能够保证在一定的时间内各 个节点之间的数据能够达成一致。如果采用强一致性,只要有一台机器宕机,那么整个集群是不可用的。
25+
26+
配置管理为了保证所有机器上的配置都是一致的,采用了强一致性共识算法。
27+

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.