File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -145,6 +145,37 @@ application.
145145
146146You 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
150181Look here: [ conreg-ui] ( https://github.com/xgpxg/conreg-ui )
Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 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
221236use crate :: conf:: { ConRegConfig , ConRegConfigWrapper } ;
222237use crate :: config:: Configs ;
You can’t perform that action at this time.
0 commit comments