Interoperability between Rust and Java

Call Dubbo services developed in Java using Rust.

1 Prerequisites

  • Install the Rust development environment
  • Install the protoc tool
  • Install the Java development environment

2 Run the Example Java Version of Dubbo Provider

The source code for the Java version of the Dubbo provider can be found at https://github.com/apache/dubbo-samples/tree/master/3-extensions/protocol/dubbo-samples-triple.

Clone the source code, compile, and run the provider:

  1. $ # clone the source code
  2. $ git clone https://github.com/apache/dubbo-samples.git
  3. $ cd dubbo-samples/dubbo-samples-triple/
  4. $ # build
  5. $ mvn clean compile package -DskipTests
  6. $ # run the provider
  7. $ java -Dprovider.port=8888 -jar ./target/dubbo-samples-triple-1.0-SNAPSHOT.jar
  8. # … omitted part of the logs
  9. Dubbo triple stub server started, port=8888

Interface definition on the Java side

3 Run the Rust Version of Dubbo Consumer

The source code for the Rust version of the Dubbo consumer can be found at https://github.com/apache/dubbo-rust/tree/main/examples/greeter.

Clone the source code, compile, and run the consumer:

  1. $ # clone the source code
  2. $ git clone https://github.com/apache/dubbo-rust.git
  3. $ cd dubbo-rust/examples/greeter/
  4. $ # build
  5. $ cargo build
  6. $ # run the consumer, call the provider
  7. $ ../../target/debug/greeter-client
  8. # unary call
  9. Response: GreeterReply { message: "hello, dubbo-rust" }
  10. # client stream
  11. client streaming, Response: GreeterReply { message: "hello client streaming" }
  12. # bi stream
  13. parts: Metadata { inner: {"content-type": "application/grpc", "date": "Wed, 28 Sep 2022 23:54:56 GMT"} }
  14. reply: GreeterReply { message: "server reply: \"msg1 from client\"" }
  15. reply: GreeterReply { message: "server reply: \"msg2 from client\"" }
  16. reply: GreeterReply { message: "server reply: \"msg3 from client\"" }
  17. trailer: Some(Metadata { inner: {"grpc-message": "poll trailer successfully.", "grpc-accept-encoding": "gzip,identity", "content-type": "application/grpc", "grpc-status": "0"} })
  18. # server stream
  19. parts: Metadata { inner: {"content-type": "application/grpc", "date": "Wed, 28 Sep 2022 23:54:56 GMT"} }
  20. reply: GreeterReply { message: "msg1 from server" }
  21. reply: GreeterReply { message: "msg2 from server" }
  22. reply: GreeterReply { message: "msg3 from server" }
  23. trailer: Some(Metadata { inner: {"content-type": "application/grpc", "grpc-message": "poll trailer successfully.", "grpc-accept-encoding": "gzip,identity", "grpc-status": "0"} })

Interface definition on the Rust side

Feedback

Was this page helpful?

Yes No

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