This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-website.git


The following commit(s) were added to refs/heads/master by this push:
     new 81f75ea697e update rust docs (#1568)
81f75ea697e is described below

commit 81f75ea697ec2e6b934144630171452baf5ab7ad
Author: Ken Liu <[email protected]>
AuthorDate: Sun Oct 23 18:23:50 2022 +0800

    update rust docs (#1568)
---
 content/zh/blog/rust/_index.md                     |   7 +
 content/zh/blog/rust/first-release.md              | Bin 0 -> 9427 bytes
 content/zh/docs3-v2/rust-sdk/quick-start.md        | 250 +--------------------
 .../rust-sdk/{quick-start.md => streaming.md}      | 101 +--------
 static/imgs/rust/dubbo-rust-mesh.png               | Bin 0 -> 777430 bytes
 static/imgs/rust/dubbo-rust-module.png             | Bin 0 -> 28826 bytes
 static/imgs/rust/dubbo-rust-tasks.png              | Bin 0 -> 261957 bytes
 7 files changed, 22 insertions(+), 336 deletions(-)

diff --git a/content/zh/blog/rust/_index.md b/content/zh/blog/rust/_index.md
new file mode 100644
index 00000000000..600d73423ed
--- /dev/null
+++ b/content/zh/blog/rust/_index.md
@@ -0,0 +1,7 @@
+
+---
+title: "Rust"
+linkTitle: "Rust"
+weight: 31
+---
+
diff --git a/content/zh/blog/rust/first-release.md 
b/content/zh/blog/rust/first-release.md
new file mode 100644
index 00000000000..13067e1ad82
Binary files /dev/null and b/content/zh/blog/rust/first-release.md differ
diff --git a/content/zh/docs3-v2/rust-sdk/quick-start.md 
b/content/zh/docs3-v2/rust-sdk/quick-start.md
index a7b15b3a0ae..c430de73b21 100644
--- a/content/zh/docs3-v2/rust-sdk/quick-start.md
+++ b/content/zh/docs3-v2/rust-sdk/quick-start.md
@@ -14,7 +14,7 @@ description: "使用 Rust 快速开发 Dubbo 服务。"
 
 ## 2 使用 IDL 定义 Dubbo 服务
 
-Greeter 服务定义如下,包含一个 Unary、Client stream、Server stream、Bidirectional stream 模型的 
Dubbo 服务。
+Greeter 服务定义如下,包含一个 Unary(request-response) 模型的 Dubbo 服务。
 
 ```protobuf
 // ./proto/greeter.proto
@@ -36,19 +36,8 @@ message GreeterReply {
 }
 
 service Greeter{
-
   // unary
   rpc greet(GreeterRequest) returns (GreeterReply);
-
-  // clientStream
-  rpc greetClientStream(stream GreeterRequest) returns (GreeterReply);
-
-  // serverStream
-  rpc greetServerStream(GreeterRequest) returns (stream GreeterReply);
-
-  // bi streaming
-  rpc greetStream(stream GreeterRequest) returns (stream GreeterReply);
-
 }
 ```
 
@@ -105,28 +94,7 @@ fn main() {
 
 ```rust
 // ./src/greeter/server.rs
-pub mod protos {
-    include!(concat!(env!("OUT_DIR"), "/org.apache.dubbo.sample.tri.rs"));
-}
-
-use futures_util::StreamExt;
-use protos::{
-    greeter_server::{register_server, Greeter},
-    GreeterReply, GreeterRequest,
-};
-
-use std::{io::ErrorKind, pin::Pin};
-
-use async_trait::async_trait;
-use futures_util::Stream;
-use tokio::sync::mpsc;
-use tokio_stream::wrappers::ReceiverStream;
-
-use dubbo_config::RootConfig;
-use dubbo::{codegen::*, Dubbo};
-
-type ResponseStream =
-    Pin<Box<dyn Stream<Item = Result<GreeterReply, dubbo::status::Status>> + 
Send>>;
+use ...
 
 #[tokio::main]
 async fn main() {
@@ -166,122 +134,6 @@ impl Greeter for GreeterServerImpl {
             message: "hello, dubbo-rust".to_string(),
         }))
     }
-
-    async fn greet_client_stream(
-        &self,
-        request: Request<Decoding<GreeterRequest>>,
-    ) -> Result<Response<GreeterReply>, dubbo::status::Status> {
-        let mut s = request.into_inner();
-        loop {
-            let result = s.next().await;
-            match result {
-                Some(Ok(val)) => println!("result: {:?}", val),
-                Some(Err(val)) => println!("err: {:?}", val),
-                None => break,
-            }
-        }
-        Ok(Response::new(GreeterReply {
-            message: "hello client streaming".to_string(),
-        }))
-    }
-
-    type greetServerStreamStream = ResponseStream;
-    async fn greet_server_stream(
-        &self,
-        request: Request<GreeterRequest>,
-    ) -> Result<Response<Self::greetServerStreamStream>, 
dubbo::status::Status> {
-        println!("greet_server_stream: {:?}", request.into_inner());
-
-        let data = vec![
-            Result::<_, dubbo::status::Status>::Ok(GreeterReply {
-                message: "msg1 from server".to_string(),
-            }),
-            Result::<_, dubbo::status::Status>::Ok(GreeterReply {
-                message: "msg2 from server".to_string(),
-            }),
-            Result::<_, dubbo::status::Status>::Ok(GreeterReply {
-                message: "msg3 from server".to_string(),
-            }),
-        ];
-        let resp = futures_util::stream::iter(data);
-
-        Ok(Response::new(Box::pin(resp)))
-    }
-
-    type greetStreamStream = ResponseStream;
-    async fn greet_stream(
-        &self,
-        request: Request<Decoding<GreeterRequest>>,
-    ) -> Result<Response<Self::greetStreamStream>, dubbo::status::Status> {
-        println!(
-            "GreeterServer::greet_stream, grpc header: {:?}",
-            request.metadata
-        );
-
-        let mut in_stream = request.into_inner();
-        let (tx, rx) = mpsc::channel(128);
-
-        // this spawn here is required if you want to handle connection error.
-        // If we just map `in_stream` and write it back as `out_stream` the 
`out_stream`
-        // will be drooped when connection error occurs and error will never 
be propagated
-        // to mapped version of `in_stream`.
-        tokio::spawn(async move {
-            while let Some(result) = in_stream.next().await {
-                match result {
-                    Ok(v) => {
-                        // if v.name.starts_with("msg2") {
-                        //     
tx.send(Err(dubbo::status::Status::internal(format!("err: args is invalid, 
{:?}", v.name))
-                        //     )).await.expect("working rx");
-                        //     continue;
-                        // }
-                        tx.send(Ok(GreeterReply {
-                            message: format!("server reply: {:?}", v.name),
-                        }))
-                        .await
-                        .expect("working rx")
-                    }
-                    Err(err) => {
-                        if let Some(io_err) = match_for_io_error(&err) {
-                            if io_err.kind() == ErrorKind::BrokenPipe {
-                                // here you can handle special case when client
-                                // disconnected in unexpected way
-                                eprintln!("\tclient disconnected: broken 
pipe");
-                                break;
-                            }
-                        }
-
-                        match tx.send(Err(err)).await {
-                            Ok(_) => (),
-                            Err(_err) => break, // response was droped
-                        }
-                    }
-                }
-            }
-            println!("\tstream ended");
-        });
-
-        // echo just write the same data that was received
-        let out_stream = ReceiverStream::new(rx);
-
-        Ok(Response::new(
-            Box::pin(out_stream) as Self::greetStreamStream
-        ))
-    }
-}
-
-fn match_for_io_error(err_status: &dubbo::status::Status) -> 
Option<&std::io::Error> {
-    let mut err: &(dyn std::error::Error + 'static) = err_status;
-
-    loop {
-        if let Some(io_err) = err.downcast_ref::<std::io::Error>() {
-            return Some(io_err);
-        }
-
-        err = match err.source() {
-            Some(err) => err,
-            None => return None,
-        };
-    }
 }
 ```
 
@@ -315,13 +167,7 @@ protocols:
 
 ```rust
 // ./src/greeter/client.rs
-pub mod protos {
-    include!(concat!(env!("OUT_DIR"), "/org.apache.dubbo.sample.tri.rs"));
-}
-
-use dubbo::codegen::*;
-use futures_util::StreamExt;
-use protos::{greeter_client::GreeterClient, GreeterRequest};
+use ...
 
 #[tokio::main]
 async fn main() {
@@ -339,81 +185,6 @@ async fn main() {
     };
     let (_parts, body) = resp.into_parts();
     println!("Response: {:?}", body);
-
-    println!("# client stream");
-    let data = vec![
-        GreeterRequest {
-            name: "msg1 from client streaming".to_string(),
-        },
-        GreeterRequest {
-            name: "msg2 from client streaming".to_string(),
-        },
-        GreeterRequest {
-            name: "msg3 from client streaming".to_string(),
-        },
-    ];
-    let req = futures_util::stream::iter(data);
-    let resp = cli.greet_client_stream(req).await;
-    let client_streaming_resp = match resp {
-        Ok(resp) => resp,
-        Err(err) => return println!("{:?}", err),
-    };
-    let (_parts, resp_body) = client_streaming_resp.into_parts();
-    println!("client streaming, Response: {:?}", resp_body);
-
-    println!("# bi stream");
-    let data = vec![
-        GreeterRequest {
-            name: "msg1 from client".to_string(),
-        },
-        GreeterRequest {
-            name: "msg2 from client".to_string(),
-        },
-        GreeterRequest {
-            name: "msg3 from client".to_string(),
-        },
-    ];
-    let req = futures_util::stream::iter(data);
-
-    let bidi_resp = cli.greet_stream(req).await.unwrap();
-
-    let (parts, mut body) = bidi_resp.into_parts();
-    println!("parts: {:?}", parts);
-    while let Some(item) = body.next().await {
-        match item {
-            Ok(v) => {
-                println!("reply: {:?}", v);
-            }
-            Err(err) => {
-                println!("err: {:?}", err);
-            }
-        }
-    }
-    let trailer = body.trailer().await.unwrap();
-    println!("trailer: {:?}", trailer);
-
-    println!("# server stream");
-    let resp = cli
-        .greet_server_stream(Request::new(GreeterRequest {
-            name: "server streaming req".to_string(),
-        }))
-        .await
-        .unwrap();
-
-    let (parts, mut body) = resp.into_parts();
-    println!("parts: {:?}", parts);
-    while let Some(item) = body.next().await {
-        match item {
-            Ok(v) => {
-                println!("reply: {:?}", v);
-            }
-            Err(err) => {
-                println!("err: {:?}", err);
-            }
-        }
-    }
-    let trailer = body.trailer().await.unwrap();
-    println!("trailer: {:?}", trailer);
 }
 ```
 
@@ -439,20 +210,5 @@ $ ./target/debug/greeter-server
 
 ```sh
 $ ./target/debug/greeter-client
-# unary call
 Response: GreeterReply { message: "hello, dubbo-rust" }
-# client stream
-client streaming, Response: GreeterReply { message: "hello client streaming" }
-# bi stream
-parts: Metadata { inner: {"content-type": "application/grpc", "date": "Wed, 28 
Sep 2022 23:34:20 GMT"} }
-reply: GreeterReply { message: "server reply: \"msg1 from client\"" }
-reply: GreeterReply { message: "server reply: \"msg2 from client\"" }
-reply: GreeterReply { message: "server reply: \"msg3 from client\"" }
-trailer: Some(Metadata { inner: {"content-type": "application/grpc", 
"grpc-status": "0", "grpc-message": "poll trailer successfully.", 
"grpc-accept-encoding": "gzip,identity"} })
-# server stream
-parts: Metadata { inner: {"content-type": "application/grpc", "date": "Wed, 28 
Sep 2022 23:34:20 GMT"} }
-reply: GreeterReply { message: "msg1 from server" }
-reply: GreeterReply { message: "msg2 from server" }
-reply: GreeterReply { message: "msg3 from server" }
-trailer: Some(Metadata { inner: {"content-type": "application/grpc", 
"grpc-status": "0", "grpc-message": "poll trailer successfully.", 
"grpc-accept-encoding": "gzip,identity"} })
 ```
diff --git a/content/zh/docs3-v2/rust-sdk/quick-start.md 
b/content/zh/docs3-v2/rust-sdk/streaming.md
similarity index 83%
copy from content/zh/docs3-v2/rust-sdk/quick-start.md
copy to content/zh/docs3-v2/rust-sdk/streaming.md
index a7b15b3a0ae..ee35e4e547d 100644
--- a/content/zh/docs3-v2/rust-sdk/quick-start.md
+++ b/content/zh/docs3-v2/rust-sdk/streaming.md
@@ -1,20 +1,16 @@
 ---
 type: docs
-title: "快速开始"
-linkTitle: "快速开始"
-weight: 1
-description: "使用 Rust 快速开发 Dubbo 服务。"
+title: "Streaming 通信模型"
+linkTitle: "Streaming通信模型"
+weight: 3
+description: "介绍使用 Dubbo Rust 快速开发 Client streaming、Server 
streaming、Bidirectional streaming 模型的服务。"
 ---
 
-请在此查看完整 [示例](https://github.com/apache/dubbo-rust/tree/main/examples/greeter)。
+本文重点讲解 Dubbo Rust Streaming 通信模式,请先查看 [Quick Start](../quick-start) 了解 Dubbo 
Rust 
基本使用,在此查看本文的[完整示例](https://github.com/apache/dubbo-rust/tree/main/examples/greeter)。
 
-## 1 前置条件
-- 安装 [Rust](https://rustup.rs/) 开发环境
-- 安装 [protoc](https://grpc.io/docs/protoc-installation/) 工具
+## 1 IDL 中增加 Streaming 模型定义
 
-## 2 使用 IDL 定义 Dubbo 服务
-
-Greeter 服务定义如下,包含一个 Unary、Client stream、Server stream、Bidirectional stream 模型的 
Dubbo 服务。
+完整 Greeter 服务定义如下,包含一个 Unary、Client stream、Server stream、Bidirectional stream 
模型的 Dubbo 服务。
 
 ```protobuf
 // ./proto/greeter.proto
@@ -52,56 +48,9 @@ service Greeter{
 }
 ```
 
-## 3 添加 Dubbo-rust 及相关依赖到项目
-```toml
-# ./Cargo.toml
-[package]
-name = "example-greeter"
-version = "0.1.0"
-edition = "2021"
-
-[[bin]]
-name = "greeter-server"
-path = "src/greeter/server.rs"
-
-[[bin]]
-name = "greeter-client"
-path = "src/greeter/client.rs"
-
-[dependencies]
-http = "0.2"
-http-body = "0.4.4"
-futures-util = {version = "0.3", default-features = false}
-tokio = { version = "1.0", features = [ "rt-multi-thread", "time", "fs", 
"macros", "net", "signal"] }
-prost-derive = {version = "0.10", optional = true}
-prost = "0.10.4"
-async-trait = "0.1.56"
-tokio-stream = "0.1"
-
-dubbo = "0.1.0"
-dubbo-config = "0.1.0"
-
-[build-dependencies]
-dubbo-build = "0.1.0"
-```
-
-## 4 配置 dubbo-build 编译 IDL
-
-在项目根目录创建 (not /src),创建 `build.rs` 文件并添加以下内容:
-
-```rust
-// ./build.rs
-fn main() {
-    dubbo_build::prost::configure()
-        .compile(&["proto/greeter.proto"], &["proto/"])
-        .unwrap();
-}
-```
-这样配置之后,编译项目就可以生成 Dubbo Stub 
相关代码,路径一般在`./target/debug/build/example-greeter-<id>/out/org.apache.dubbo.sample.tri.rs`。
-
-## 5 编写 Dubbo 业务代码
+## 2 使用 Streaming 模型定义编写逻辑
 
-### 5.1 编写 Dubbo Server
+### 2.1 编写 Streaming Server
 
 ```rust
 // ./src/greeter/server.rs
@@ -285,33 +234,7 @@ fn match_for_io_error(err_status: &dubbo::status::Status) 
-> Option<&std::io::Er
 }
 ```
 
-### 5.2 配置dubbo.yaml
-
-dubbo.yaml指示server端的配置,包括暴露的服务列表、协议配置、监听配置等。
-
-```yaml
-# ./dubbo.yaml
-name: dubbo
-service:
-  org.apache.dubbo.sample.tri.Greeter:
-    version: 1.0.0
-    group: test
-    protocol: triple
-    registry: ''
-    serializer: json
-    protocol_configs:
-      triple:
-        ip: 0.0.0.0
-        port: '8888'
-        name: triple
-protocols:
-  triple:
-    ip: 0.0.0.0
-    port: '8888'
-    name: triple
-```
-
-### 5.3 编写 Dubbo Client
+### 2.2 编写 Streaming Client
 
 ```rust
 // ./src/greeter/client.rs
@@ -417,7 +340,7 @@ async fn main() {
 }
 ```
 
-## 6 运行并总结
+## 3 运行示例
 
 1. 编译
 
@@ -432,7 +355,7 @@ $ ./target/debug/greeter-server
 2022-09-28T23:33:28.104577Z  INFO dubbo::framework: url: Some(Url { uri: 
"triple://0.0.0.0:8888/org.apache.dubbo.sample.tri.Greeter", protocol: 
"triple", location: "0.0.0.0:8888", ip: "0.0.0.0", port: "8888", service_key: 
["org.apache.dubbo.sample.tri.Greeter"], params: {} })
 ```
 
-3. 运行client,验证调用是否成功
+3. 运行client,可以看到 Streaming 通信效果
 
 
执行`./target/debug/greeter-client`来运行client,调用`triple://127.0.0.1:8888/org.apache.dubbo.sample.tri.Greeter`下的各种方法:
 
diff --git a/static/imgs/rust/dubbo-rust-mesh.png 
b/static/imgs/rust/dubbo-rust-mesh.png
new file mode 100644
index 00000000000..a9164bb6423
Binary files /dev/null and b/static/imgs/rust/dubbo-rust-mesh.png differ
diff --git a/static/imgs/rust/dubbo-rust-module.png 
b/static/imgs/rust/dubbo-rust-module.png
new file mode 100755
index 00000000000..e667f33d907
Binary files /dev/null and b/static/imgs/rust/dubbo-rust-module.png differ
diff --git a/static/imgs/rust/dubbo-rust-tasks.png 
b/static/imgs/rust/dubbo-rust-tasks.png
new file mode 100755
index 00000000000..19edf475fac
Binary files /dev/null and b/static/imgs/rust/dubbo-rust-tasks.png differ

Reply via email to