Communication using Unix Socket Connector

Introduction to using the Dubbo Rust Triple protocol to implement communication via the Unix socket connector.

This article focuses on using the Dubbo Rust Triple protocol with Unix sockets. Please refer to the Quick Start for basic usage of Dubbo Rust, and you can see the complete example here.

1 Explanation of Using Unix Socket Connector

[cfg(any(target_os = “macos”, target_os=“unix”))] The unix module will be compiled for use when the operating system meets the cfg configuration, otherwise it cannot be used.

2 Logic for Using Unix Socket Connector with client/connection

2.1 Writing the Client Side

  1. // examples/echo/src/echo/client.rs
  2. // Initialize Client using ClientBuilder
  3. let builder = ClientBuilder::new().with_connector("unix").with_host("unix://127.0.0.1:8888");
  4. let mut cli = EchoClient::build(builder);

2.2 Writing the Server Side

  1. // examples/echo/src/echo/server.rs
  2. // Initialize Server using serverbuilder
  3. let builder = ServerBuilder::new()
  4. .with_listener("unix".to_string())
  5. .with_service_names(vec!["grpc.examples.echo.Echo".to_string()])
  6. .with_addr("127.0.0.1:8888");
  7. builder.build().serve().await.unwrap();

3 Running Example

  1. Compile

Run cargo build to compile the server and client.

  1. Run the server

Run cargo run --bin echo-server to start the server. As configured in the dubbo.yaml above, the server will listen on port 8888 and provide RPC services using the triple protocol:

  1. $ cargo run --bin echo-server
  2. 2023-01-19T08:36:25.663138Z INFO dubbo::triple::server::builder: server starting. addr: Some(127.0.0.1:8888)
  1. Run the client to see Unix communication in action

Run cargo run --bin echo-client to start the client, calling various methods under triple://127.0.0.1:8888/org.apache.dubbo.sample.tri.Greeter:

  1. $ cargo run --bin echo-client
  2. 2023-01-19T08:38:52.516792Z INFO dubbo::triple::transport::connector::unix_connector: host is ip address: "127.0.0.1"
  3. Response: EchoResponse { message: "hello, dubbo-rust" }
  4. 2023-01-19T08:38:52.526697Z INFO dubbo::triple::transport::connector::unix_connector: host is ip address: "127.0.0.1"
  5. client streaming, Response: EchoResponse { message: "hello client streaming" }
  6. 2023-01-19T08:38:52.539439Z INFO dubbo::triple::transport::connector::unix_connector: host is ip address: "127.0.0.1"
  7. parts: Metadata { inner: {"content-type": "application/grpc", "date": "Thu, 19 Jan 2023 08:38:52 GMT"} }
  8. reply: EchoResponse { message: "server reply: \"msg1 from client\"" }
  9. reply: EchoResponse { message: "server reply: \"msg2 from client\"" }
  10. reply: EchoResponse { message: "server reply: \"msg3 from client\"" }
  11. trailer: Some(Metadata { inner: {"grpc-accept-encoding": "gzip,identity", "grpc-status": "0", "grpc-message": "poll trailer successfully.", "content-type": "application/grpc"} })
  12. 2023-01-19T08:38:52.645035Z INFO dubbo::triple::transport::connector::unix_connector: host is ip address: "127.0.0.1"
  13. parts: Metadata { inner: {"content-type": "application/grpc", "date": "Thu, 19 Jan 2023 08:38:52 GMT"} }
  14. reply: EchoResponse { message: "msg1 from server" }
  15. reply: EchoResponse { message: "msg2 from server" }
  16. reply: EchoResponse { message: "msg3 from server" }
  17. trailer: Some(Metadata { inner: {"grpc-status": "0", "content-type": "application/grpc", "grpc-message": "poll trailer successfully.", "grpc-accept-encoding": "gzip,identity"} })

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)