添加:ZHub 管理接口文档和客户端使用指南
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
---
|
||||
sidebar_position: 1
|
||||
title: IType 类型定义
|
||||
description: ZHub 客户端 IType 接口类型定义
|
||||
---
|
||||
|
||||
# IType
|
||||
# IType 类型定义
|
||||
|
||||
> IType 中实现的 TypeToken
|
||||
IType 接口提供了 ZHub 客户端中常用的类型定义,用于 RPC 调用和消息订阅时的类型安全。
|
||||
|
||||
## 接口定义
|
||||
|
||||
```java
|
||||
package dev.zhub;
|
||||
@@ -24,6 +28,49 @@ public interface IType {
|
||||
}
|
||||
```
|
||||
|
||||
## 使用示例
|
||||
|
||||
### RPC 调用
|
||||
```java
|
||||
// 字符串类型 RPC
|
||||
RpcResult<String> result = zhub.rpc("user.getInfo", "user123", IType.STRING);
|
||||
|
||||
// 整数类型 RPC
|
||||
RpcResult<Integer> count = zhub.rpc("user.getCount", "group1", IType.INT);
|
||||
|
||||
// Map 类型 RPC
|
||||
RpcResult<Map<String, String>> userInfo = zhub.rpc("user.getDetails", "user123", IType.MAP);
|
||||
```
|
||||
|
||||
### 消息订阅
|
||||
```java
|
||||
// 订阅字符串消息
|
||||
zhub.subscribe("user.notification", message -> {
|
||||
System.out.println("收到通知: " + message);
|
||||
});
|
||||
|
||||
// 订阅 Map 消息
|
||||
zhub.subscribe("user.profile", IType.MAP, profile -> {
|
||||
System.out.println("用户资料: " + profile.get("name"));
|
||||
});
|
||||
|
||||
// 订阅整数消息
|
||||
zhub.subscribe("user.count", IType.INT, count -> {
|
||||
System.out.println("用户数: " + count);
|
||||
});
|
||||
```
|
||||
|
||||
## 类型说明
|
||||
|
||||
- `STRING` - 字符串类型,用于文本消息
|
||||
- `INT` - 整数类型,用于计数器、ID
|
||||
- `LONG` - 长整数类型,用于时间戳、大数值
|
||||
- `DOUBLE` - 双精度浮点类型,用于价格、比率
|
||||
- `MAP` - 键值对映射,用于结构化数据
|
||||
- `LMAP` - Map 列表,用于批量数据
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 优先使用 IType 中提供的类型
|
||||
- 自定义类型使用 `new TypeToken<Type>(){}` 构建
|
||||
- 字符串消息默认类型`new TypeToken<String>(){}`,无需显式声明
|
||||
|
||||
Reference in New Issue
Block a user