补充:ZHub 的rpc使用
This commit is contained in:
parent
621ca23432
commit
bee336ed5e
@ -2,6 +2,7 @@
|
||||
"label": "其他组件",
|
||||
"position": 3,
|
||||
"link": {
|
||||
"type": "generated-index"
|
||||
"type": "generated-index",
|
||||
"description": "分布式系统常用组件"
|
||||
}
|
||||
}
|
||||
|
@ -4,4 +4,28 @@ sidebar_position: 1
|
||||
|
||||
# RPC远程调用
|
||||
|
||||
#
|
||||
## 什么是 RPC
|
||||
> RPC 是一种通过网络将远程过程调用(Remote Procedure Call,RPC)封装成消息,并传送到远程服务器上的过程。
|
||||
> 
|
||||
|
||||
## 使用场景
|
||||
> 在分布式环境下,通过 RPC 可以在两个应用之间进行消息传递,实现远程调用。
|
||||
|
||||
## rpc的订阅-调用基础示例
|
||||
### 被调用端
|
||||
```java
|
||||
// 订阅 rpc-b 事件, 参数类型为 String
|
||||
zhub.rpcSubscribe("rpc-b", IType.STRING, r -> {
|
||||
String str = r.getValue();
|
||||
System.out.println("接收到 b 事件:" + str);
|
||||
return r.render("接收到 b 事件:" + str);
|
||||
});
|
||||
```
|
||||
### 调用端
|
||||
```java
|
||||
// 调用 rpc-b 事件, 参数类型为 String,返回类型为 String
|
||||
RpcResult<String> rpcResult = zhub.rpc("rpc-b", "hello rpc", IType.STRING);
|
||||
String result = rpcResult.getResult();
|
||||
System.out.println("rpc result:" + result);
|
||||
```
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user