Skip to content

Commit 34e1caa

Browse files
authored
[type:feat] Add rust client doc . (#1037)
* add team mdx +1. * ci * ci+1 * refactor to rust code mode.
1 parent 9088a76 commit 34e1caa

File tree

4 files changed

+351
-0
lines changed

4 files changed

+351
-0
lines changed

docusaurus.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,21 @@ module.exports = {
211211
showLastUpdateTime: true,
212212
},
213213
],
214+
[
215+
"@docusaurus/plugin-content-docs",
216+
{
217+
id: "shenyuClientRust",
218+
path: "shenyuClientRust",
219+
routeBasePath: "shenyuClientRust",
220+
disableVersioning: false,
221+
includeCurrentVersion: true,
222+
editCurrentVersion: true,
223+
editLocalizedFiles: true,
224+
sidebarPath: require.resolve("./sidebarsCommunity.js"),
225+
showLastUpdateAuthor: true,
226+
showLastUpdateTime: true,
227+
},
228+
],
214229
[
215230
"@docusaurus/plugin-content-docs",
216231
{

shenyuClientRust/http.md

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
description: http
3+
title: Http Example
4+
---
5+
# The Http type Register
6+
7+
**1.Fist make sure The ShenYuAdmin is Started, and ShenYuAdmin service active port is 9095.**
8+
9+
```log
10+
//Or you will see this error :
11+
12+
2024-10-09T07:23:26.970200Z ERROR shenyu_client_rust::core: Can't get register token
13+
2024-10-09T07:23:29.015550Z ERROR shenyu_client_rust::core: [ERROR], register metadata to http://127.0.0.1:9095/shenyu-client/register-metadata failed, app_name: shenyu_client_app, path: /health, contextPath: /xxx
14+
2024-10-09T07:23:31.039558Z ERROR shenyu_client_rust::core: [ERROR], register metadata to http://127.0.0.1:9095/shenyu-client/register-metadata failed, app_name: shenyu_client_app, path: /users, contextPath: /xxx
15+
2024-10-09T07:23:33.089412Z ERROR shenyu_client_rust::core: [ERROR], register uri to http://127.0.0.1:9095/shenyu-client/register-uri failed, app_name: shenyu_client_app, host: 10.10.9.198, port: 3000
16+
2024-10-09T07:23:35.124249Z ERROR shenyu_client_rust::core: [ERROR], register discover config to http://127.0.0.1:9095/shenyu-client/register-discoveryConfig failed, discovery_type: zookeeper, host: 10.10.9.198, port: 3000
17+
18+
```
19+
20+
**2.Step 1 Get shenyu_admin_client. (Register service need this)**
21+
22+
```yml
23+
# a yml-format config file
24+
shenyu:
25+
register:
26+
register_type: "http"
27+
servers: "http://127.0.0.1:9095"
28+
props:
29+
username: "admin"
30+
password: "123456"
31+
```
32+
33+
```rust
34+
fn register_test() {
35+
//init config.
36+
let config = ShenYuConfig::from_yaml_file("config.yml").unwrap();
37+
// init shenyu client.
38+
let client = ShenyuClient::new(config, app.app_name(), app.uri_infos(), 3000).unwrap();
39+
/// other steps.
40+
}
41+
```
42+
43+
```
44+
The adminToken like this :
45+
{
46+
"code":200,
47+
"message":"login dashboard user success",
48+
"data":{
49+
"id":"1",
50+
"userName":"admin",
51+
"role":1,
52+
"enabled":true,
53+
"dateCreated":"2018-06-23 15:12:22",
54+
"dateUpdated":"2024-10-03 02:29:39",
55+
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNzI4NTQ3NjQ3fQ.93LAuDP_MrJZeQB5A6gX-3-Vyxy9egw41QhnNHlUWEE"
56+
}
57+
}
58+
59+
When you success get toekn, you will see this :
60+
2024-10-09T08:07:27.721483Z INFO shenyu_client_rust::core: [SUCCESS], get register token success, register token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNzI4NTQ3NjQ3fQ.93LAuDP_MrJZeQB5A6gX-3-Vyxy9egw41QhnNHlUWEE"
61+
```
62+
63+
**3.Step 2 Register to ShenYu admin. (maybe add the admin sync data to gateway doc url).**
64+
65+
```rust
66+
fn register_test() {
67+
/// Step1.
68+
// register to shenyu admin.
69+
client.register().expect("TODO: panic message");
70+
}
71+
```
72+
73+
```log
74+
2024-10-03T02:29:39.392390Z INFO shenyu_client_rust::core: [SUCCESS], register metadata success, register data: Object {
75+
"appName": String("shenyu_client_app"),
76+
"contextPath": String("/xxx"),
77+
"enabled": Bool(true),
78+
"host": String("10.1.0.187"),
79+
"methodName": String("get"),
80+
"parameterTypes": String(""),
81+
"path": String("/xxx/health"),
82+
"pathDesc": String(""),
83+
"pluginNames": Array [],
84+
"port": Number(4000),
85+
"registerMetaData": String(""),
86+
"rpcExt": String(""),
87+
"rpcType": String("http"),
88+
"ruleName": String("/xxx/health"),
89+
"serviceName": String("shenyu_client_app"),
90+
}
91+
2024-10-03T02:29:39.398917Z INFO shenyu_client_rust::core: [SUCCESS], register metadata success, register data: Object {
92+
"appName": String("shenyu_client_app"),
93+
"contextPath": String("/xxx"),
94+
"enabled": Bool(true),
95+
"host": String("10.1.0.187"),
96+
"methodName": String("post"),
97+
"parameterTypes": String(""),
98+
"path": String("/xxx/create_user"),
99+
"pathDesc": String(""),
100+
"pluginNames": Array [],
101+
"port": Number(4000),
102+
"registerMetaData": String(""),
103+
"rpcExt": String(""),
104+
"rpcType": String("http"),
105+
"ruleName": String("/xxx/create_user"),
106+
"serviceName": String("shenyu_client_app"),
107+
}
108+
2024-10-03T02:29:39.404389Z INFO shenyu_client_rust::core: [SUCCESS], register metadata success, register data: Object {
109+
"appName": String("shenyu_client_app"),
110+
"contextPath": String("/xxx"),
111+
"enabled": Bool(true),
112+
"host": String("10.1.0.187"),
113+
"methodName": String("get"),
114+
"parameterTypes": String(""),
115+
"path": String("/xxx/"),
116+
"pathDesc": String(""),
117+
"pluginNames": Array [],
118+
"port": Number(4000),
119+
"registerMetaData": String(""),
120+
"rpcExt": String(""),
121+
"rpcType": String("http"),
122+
"ruleName": String("/xxx/"),
123+
"serviceName": String("shenyu_client_app"),
124+
}
125+
2024-10-03T02:29:39.409866Z INFO shenyu_client_rust::core: [SUCCESS], register uri success, register data: Object {
126+
"appName": String("shenyu_client_app"),
127+
"contextPath": String("/xxx"),
128+
"eventType": String("REGISTER"),
129+
"host": String("10.1.0.187"),
130+
"port": Number(4000),
131+
"protocol": String("http"),
132+
"rpcType": String("http"),
133+
}
134+
2024-10-03T02:29:39.433662Z INFO shenyu_client_rust::core: [SUCCESS], register discover config success, register data: Object {
135+
"discoveryType": String("zookeeper"),
136+
"handler": String("{}"),
137+
"listenerNode": String("/shenyu/discovery/http_example"),
138+
"name": String("defaultzookeeper"),
139+
"pluginName": String(""),
140+
"props": Object {
141+
"baseSleepTimeMilliseconds": String("1000"),
142+
"connectionTimeoutMilliseconds": String("60000"),
143+
"maxRetries": String("4"),
144+
"maxSleepTimeMilliseconds": String("5000"),
145+
"sessionTimeoutMilliseconds": String("8"),
146+
},
147+
"selectorName": String("/xxx"),
148+
"serverList": String("127.0.0.1:2181"),
149+
}
150+
151+
```
152+
153+
**3.Step 3 Offline register from ShenYu GateWay.**
154+
155+
```log
156+
2024-10-03T02:29:50.311159Z INFO shenyu_client_rust::core: [SUCCESS], offline success, register data: Object {
157+
"appName": String("shenyu_client_app"),
158+
"contextPath": String("/xxx"),
159+
"eventType": String("REGISTER"),
160+
"host": String("10.1.0.187"),
161+
"port": Number(4000),
162+
"protocol": String("http"),
163+
}
164+
```
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
---
2+
description: http
3+
title: Http Example
4+
---
5+
# The Http type Register
6+
7+
**1.Fist make sure The ShenYuAdmin is Started, and ShenYuAdmin service active port is 9095.**
8+
9+
```log
10+
//Or you will see this error :
11+
12+
2024-10-09T07:23:26.970200Z ERROR shenyu_client_rust::core: Can't get register token
13+
2024-10-09T07:23:29.015550Z ERROR shenyu_client_rust::core: [ERROR], register metadata to http://127.0.0.1:9095/shenyu-client/register-metadata failed, app_name: shenyu_client_app, path: /health, contextPath: /xxx
14+
2024-10-09T07:23:31.039558Z ERROR shenyu_client_rust::core: [ERROR], register metadata to http://127.0.0.1:9095/shenyu-client/register-metadata failed, app_name: shenyu_client_app, path: /users, contextPath: /xxx
15+
2024-10-09T07:23:33.089412Z ERROR shenyu_client_rust::core: [ERROR], register uri to http://127.0.0.1:9095/shenyu-client/register-uri failed, app_name: shenyu_client_app, host: 10.10.9.198, port: 3000
16+
2024-10-09T07:23:35.124249Z ERROR shenyu_client_rust::core: [ERROR], register discover config to http://127.0.0.1:9095/shenyu-client/register-discoveryConfig failed, discovery_type: zookeeper, host: 10.10.9.198, port: 3000
17+
18+
```
19+
20+
**2.Step 1 Get shenyu_admin_client. (Register service need this)**
21+
22+
```yml
23+
# a yml-format config file
24+
shenyu:
25+
register:
26+
register_type: "http"
27+
servers: "http://127.0.0.1:9095"
28+
props:
29+
username: "admin"
30+
password: "123456"
31+
```
32+
33+
```rust
34+
fn register_test() {
35+
//init config.
36+
let config = ShenYuConfig::from_yaml_file("config.yml").unwrap();
37+
// init shenyu client.
38+
let client = ShenyuClient::new(config, app.app_name(), app.uri_infos(), 3000).unwrap();
39+
/// other steps.
40+
}
41+
```
42+
43+
```
44+
The adminToken like this :
45+
{
46+
"code":200,
47+
"message":"login dashboard user success",
48+
"data":{
49+
"id":"1",
50+
"userName":"admin",
51+
"role":1,
52+
"enabled":true,
53+
"dateCreated":"2018-06-23 15:12:22",
54+
"dateUpdated":"2024-10-03 02:29:39",
55+
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNzI4NTQ3NjQ3fQ.93LAuDP_MrJZeQB5A6gX-3-Vyxy9egw41QhnNHlUWEE"
56+
}
57+
}
58+
59+
When you success get toekn, you will see this :
60+
2024-10-09T08:07:27.721483Z INFO shenyu_client_rust::core: [SUCCESS], get register token success, register token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImFkbWluIiwiZXhwIjoxNzI4NTQ3NjQ3fQ.93LAuDP_MrJZeQB5A6gX-3-Vyxy9egw41QhnNHlUWEE"
61+
```
62+
63+
**3.Step 2 Register to ShenYu admin. (maybe add the admin sync data to gateway doc url).**
64+
65+
```rust
66+
fn register_test() {
67+
/// Step1.
68+
// register to shenyu admin.
69+
client.register().expect("TODO: panic message");
70+
}
71+
```
72+
73+
```log
74+
2024-10-03T02:29:39.392390Z INFO shenyu_client_rust::core: [SUCCESS], register metadata success, register data: Object {
75+
"appName": String("shenyu_client_app"),
76+
"contextPath": String("/xxx"),
77+
"enabled": Bool(true),
78+
"host": String("10.1.0.187"),
79+
"methodName": String("get"),
80+
"parameterTypes": String(""),
81+
"path": String("/xxx/health"),
82+
"pathDesc": String(""),
83+
"pluginNames": Array [],
84+
"port": Number(4000),
85+
"registerMetaData": String(""),
86+
"rpcExt": String(""),
87+
"rpcType": String("http"),
88+
"ruleName": String("/xxx/health"),
89+
"serviceName": String("shenyu_client_app"),
90+
}
91+
2024-10-03T02:29:39.398917Z INFO shenyu_client_rust::core: [SUCCESS], register metadata success, register data: Object {
92+
"appName": String("shenyu_client_app"),
93+
"contextPath": String("/xxx"),
94+
"enabled": Bool(true),
95+
"host": String("10.1.0.187"),
96+
"methodName": String("post"),
97+
"parameterTypes": String(""),
98+
"path": String("/xxx/create_user"),
99+
"pathDesc": String(""),
100+
"pluginNames": Array [],
101+
"port": Number(4000),
102+
"registerMetaData": String(""),
103+
"rpcExt": String(""),
104+
"rpcType": String("http"),
105+
"ruleName": String("/xxx/create_user"),
106+
"serviceName": String("shenyu_client_app"),
107+
}
108+
2024-10-03T02:29:39.404389Z INFO shenyu_client_rust::core: [SUCCESS], register metadata success, register data: Object {
109+
"appName": String("shenyu_client_app"),
110+
"contextPath": String("/xxx"),
111+
"enabled": Bool(true),
112+
"host": String("10.1.0.187"),
113+
"methodName": String("get"),
114+
"parameterTypes": String(""),
115+
"path": String("/xxx/"),
116+
"pathDesc": String(""),
117+
"pluginNames": Array [],
118+
"port": Number(4000),
119+
"registerMetaData": String(""),
120+
"rpcExt": String(""),
121+
"rpcType": String("http"),
122+
"ruleName": String("/xxx/"),
123+
"serviceName": String("shenyu_client_app"),
124+
}
125+
2024-10-03T02:29:39.409866Z INFO shenyu_client_rust::core: [SUCCESS], register uri success, register data: Object {
126+
"appName": String("shenyu_client_app"),
127+
"contextPath": String("/xxx"),
128+
"eventType": String("REGISTER"),
129+
"host": String("10.1.0.187"),
130+
"port": Number(4000),
131+
"protocol": String("http"),
132+
"rpcType": String("http"),
133+
}
134+
2024-10-03T02:29:39.433662Z INFO shenyu_client_rust::core: [SUCCESS], register discover config success, register data: Object {
135+
"discoveryType": String("zookeeper"),
136+
"handler": String("{}"),
137+
"listenerNode": String("/shenyu/discovery/http_example"),
138+
"name": String("defaultzookeeper"),
139+
"pluginName": String(""),
140+
"props": Object {
141+
"baseSleepTimeMilliseconds": String("1000"),
142+
"connectionTimeoutMilliseconds": String("60000"),
143+
"maxRetries": String("4"),
144+
"maxSleepTimeMilliseconds": String("5000"),
145+
"sessionTimeoutMilliseconds": String("8"),
146+
},
147+
"selectorName": String("/xxx"),
148+
"serverList": String("127.0.0.1:2181"),
149+
}
150+
151+
```
152+
153+
**3.Step 3 Offline register from ShenYu GateWay.**
154+
155+
```log
156+
2024-10-03T02:29:50.311159Z INFO shenyu_client_rust::core: [SUCCESS], offline success, register data: Object {
157+
"appName": String("shenyu_client_app"),
158+
"contextPath": String("/xxx"),
159+
"eventType": String("REGISTER"),
160+
"host": String("10.1.0.187"),
161+
"port": Number(4000),
162+
"protocol": String("http"),
163+
}
164+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"version-0.2.0/tutorialSidebar": [
3+
{
4+
"type": "autogenerated",
5+
"dirName": "."
6+
}
7+
]
8+
}

0 commit comments

Comments
 (0)