Skip to content

Commit 2c32c8f

Browse files
committed
docs(client): update docs
1 parent 8cfc9da commit 2c32c8f

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,37 @@ application.
145145

146146
You can view the detailed documentation from [conreg-client](https://docs.rs/conreg-client)
147147

148+
## Feign-like
149+
150+
[conreg-feign-macro](https://docs.rs/conreg-feign-macro) provides a macro that implements functionality similar to
151+
Java's Feign, enabling remote procedure calls across micros
152+
153+
enable `feign` feature to enable the macro.
154+
155+
```toml
156+
[dependencies]
157+
conreg-client = { version = "*", features = ["feign", "tracing"] }
158+
```
159+
160+
Example:
161+
162+
```rust
163+
#[feign_client(service_id = "user-service", base_path = "/api")]
164+
trait UserService {
165+
#[get("/api/users/{id}")]
166+
async fn get_user(&self, id: i32) -> Result<String, FeignError>;
167+
168+
// ... other methods
169+
}
170+
171+
// Then, you can use the generated client like this:
172+
#[tokio::main]
173+
async fn main() {
174+
let client = UserServiceImpl::default();
175+
let user = client.get_user(1).await?;
176+
}
177+
```
178+
148179
# UI
149180

150181
Look here: [conreg-ui](https://github.com/xgpxg/conreg-ui)

README_zh.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,37 @@ conreg-client 是 Conreg 的客户端 SDK,用于集成到您的 Rust 应用程
141141

142142
您可以从 [conreg-client](https://docs.rs/conreg-client) 查看详细文档
143143

144+
145+
## Feign 风格客户端
146+
147+
[conreg-feign-macro](https://docs.rs/conreg-feign-macro) 提供了一个宏,实现了类似 Java Feign,支持微服务间的远程过程调用。
148+
149+
启用 `feign` 特性来开启此功能:
150+
151+
```toml
152+
[dependencies]
153+
conreg-client = { version = "*", features = ["feign", "tracing"] }
154+
```
155+
156+
示例:
157+
158+
```rust
159+
#[feign_client(service_id = "user-service", base_path = "/api")]
160+
trait UserService {
161+
#[get("/api/users/{id}")]
162+
async fn get_user(&self, id: i32) -> Result<String, FeignError>;
163+
164+
// ... 其他方法
165+
}
166+
167+
// 然后,可以像这样使用生成的接口:
168+
#[tokio::main]
169+
async fn main() {
170+
let client = UserServiceImpl::default();
171+
let user = client.get_user(1).await.unwrap();
172+
}
173+
```
174+
144175
# 用户界面
145176

146177
详情请见:[conreg-ui](https://github.com/xgpxg/conreg-ui)

conreg-client/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,21 @@
217217
//!
218218
//! # Feign-like Component
219219
//! [conreg-feign-macro](https://docs.rs/conreg-feign-macro) provides a macro that implements functionality similar to Java's Feign, enabling remote procedure calls across microservices.
220+
//!
221+
//! Example:
222+
//! ```rust
223+
//! #[feign_client(service_id = "user-service", base_path = "/api")]
224+
//! trait UserService{
225+
//! #[get("/api/users/{id}")]
226+
//! async fn get_user(&self, id: i32) -> Result<String, FeignError>;
227+
//!
228+
//! // ... other methods
229+
//! }
230+
//!
231+
//! // Then, you can use the generated client like this:
232+
//! let client = UserServiceImpl::default();
233+
//! let user = client.get_user(1).await?;
234+
//! ```
220235
221236
use crate::conf::{ConRegConfig, ConRegConfigWrapper};
222237
use crate::config::Configs;

0 commit comments

Comments
 (0)