Non-Protobuf Mode Protocol Interoperability (Applicable to Old Version Dubbo Java Applications)

If you are an old user of Dubbo Java, your Dubbo Java application may not be using Protobuf (defining services directly using Java interfaces). In this case, you need to develop the Dubbo Go-client as follows to call the older version of Dubbo services.

Note

Before reading this document, please remember that we recommend using the protobuf+triple model to write services that are interoperable between Java and Go. This article only applies if you already have an old version of a Dubbo Java application; otherwise, please refer to the previous documentation for developing services using protobuf+triple.

You can view the complete example source code here.

Go-client Calling Java-server

If you are an old user of Dubbo Java, your Dubbo Java application may not be using Protobuf (defining services directly using Java interfaces). In this case, you need to develop the Dubbo Go-client as follows to call the older version of Dubbo services.

The following solutions support both triple (non-Protobuf) and Dubbo protocols; you only need to adjust the protocol configuration client.WithClientProtocolTriple().

Assuming our current Java service is defined as follows:

  1. package org.apache.dubbo.samples.api;
  2. public interface GreetingsService {
  3. String sayHi(String name);
  4. }

We need to write the Go-client as follows to achieve service invocation:

  1. // Generate shared client, specify
  2. cliDubbo, _ := client.NewClient(
  3. client.WithClientProtocolDubbo(),
  4. client.WithClientSerialization(constant.Hessian2Serialization),
  5. )
  6. // Generate service proxy, specifying the full path name of the Java service
  7. connDubbo, _ := cliDubbo.Dial("org.apache.dubbo.samples.api.GreetingsService", client.WithURL("tri://localhost:50052"))
  8. var respDubbo string
  9. // Initiate call, parameters specified as an array (standard JSON format, refer to Java generic calls)
  10. connDubbo.CallUnary(context.Background(), []interface{}{"hello"}, &respDubbo, "SayHello")

Next, let’s try running the example:

  1. Run the Java server
  1. ./java/java-server/run.sh

Check if the service is running properly:

  1. curl \
  2. --header "Content-Type: application/json" \
  3. --data '{"name": "Dubbo"}' \
  4. http://localhost:50052/org.apache.dubbo.sample.Greeter/sayHello
  1. Run the Go client
  1. go run go/go-server/cmd/client.go

Java-client Calling Go-server

In this scenario, it means you need to develop the Go server service entirely from scratch. We recommend directly using Protobuf to develop the Go server service, and the Java client side should also use Protobuf to invoke the new service. For specific usage examples, please refer to the previous documentation.

Feedback

Was this page helpful?

Yes No

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