Skip to content

Commit bf86adc

Browse files
committed
modify rpc example: compare to consumer/producer
1 parent 66412cc commit bf86adc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

_posts/2023-02-26-rpc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ rpc虽然模仿ipc未遂(“像调用本地方法一样”),性能上做
232232
三大问题的解决方案:
233233
1. 数据表示:文本。直接在json里写上具体的参数值(params)、返回值(result);
234234
2. 数据传输:比如http;
235-
3. 方法表示:文本。直接在json里写上方法名(method);
235+
3. 方法表示:文本。直接在json里写上方法名(method,甚至都不用写参数类型,看来是不支持重名方法的。当然方法也是全局的,没有类的概念);
236236

237237
json-rpc只规定了使用json进行数据表示,并没有限定具体传输协议:
238238
> It is transport agnostic in that the concepts can be used within the same process, over sockets, over http, or in many various message passing environments.

_posts/2023-03-01-rpc-example.md

+8
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ public interface SchoolService {
194194

195195
**所以关键是要让server知道协议里用的哪个类,server只要能明白就行。client和server用同一个类作为协议只是其中最简单的一种实现罢了。**
196196

197+
> 毕竟在json-rpc里,直接用json格式告诉server用的是哪个方法也是可以的(甚至连参数类型都不用提,说明不支持override,也没有类的概念,真简单)。
198+
197199

198200
# Thrift
199201
来看看Facebook的[Thrift](https://thrift.apache.org/)。
@@ -447,6 +449,12 @@ public class Test {
447449

448450
> 想具有主动通知的功能,比如zookeeper,则zk的client里也必须有一个监听线程。
449451

452+
其实这就是个生产者消费者模型:
453+
1, rpc client作为消费者,向rpc server请求资源(本次rpc调用的结果),并wait在callback上;
454+
1, rpc client里的接收rpc server结果的通知线程作为生产者,根据request id找到消费者线程,并唤醒;
455+
456+
和普通生产者比起来,这里的生产者稍显抽象,它是要接收rpc server的结果之后才能产生新的资源。
457+
450458
## 发布服务
451459
无需多言,zookeeper等服务注册中心。
452460

0 commit comments

Comments
 (0)