Skip to content

Commit

Permalink
update sample
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenlj committed Oct 24, 2023
1 parent c860a12 commit 3be5f20
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
13 changes: 12 additions & 1 deletion 1-basic/dubbo-samples-api/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# About this sample

This sample code demonstrates building up dubbo service provider and service consumer with the pure API approach. In this example, multicast is facilitated as the registration mechanism, therefore it is necessary to explicitly specify system property `java.net.preferIPv4Stack`.
This example demonstrates building up of Dubbo rpc server and client with lightweight API. The API is quite simple and straightforward.

Follow steps below to run this example.

## Start Server
Run the command below to start the Dubbo rpc server

```bash
mvn clean package
mvn -Dexec.mainClass=org.apache.dubbo.samples.provider.Application exec:java
```

Now, you have a server running on port 50052 which accepts triple protocol requests.

More usages of triple protocol can be found here:
* [Triple with Protobuf (IDL mode)](../dubbo-samples-idl/)
* [Streaming RPCs](../../2-advanced/dubbo-samples-triple-streaming/)
* [Interoperability with standard gRPC clients and servers](../../2-advanced/dubbo-samples-triple-grpc/)
* [Using triple with other languages and browser](https://dubbo.apache.org/zh-cn/overview/mannual/)

## Start Client

There are two ways to test the server works as expected:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,23 @@
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.bootstrap.builders.ReferenceBuilder;
import org.apache.dubbo.samples.api.GreetingsService;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

public class GreetingServiceIT {
private static String zookeeperHost = System.getProperty("zookeeper.address", "127.0.0.1");

@Test
public void test() {
ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
reference.setApplication(new ApplicationConfig("first-dubbo-consumer"));
reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181"));
reference.setInterface(GreetingsService.class);
ReferenceConfig<GreetingsService> reference =
ReferenceBuilder.<GreetingsService>newBuilder()
.interfaceClass(GreetingsService.class)
.url("tri://localhost:50052")
.build();
DubboBootstrap.getInstance().reference(reference).start();
GreetingsService service = reference.get();

String message = service.sayHi("dubbo");
Assertions.assertEquals(message, "hi, dubbo");
}
Expand Down
2 changes: 1 addition & 1 deletion 1-basic/dubbo-samples-idl/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Dubbo Triple Example
# Dubbo Triple With Protobuf

This example shows the basic usage of Triple protocol with a typical request-response model demo that uses IDL as the method of defining Dubbo service.

Expand Down

0 comments on commit 3be5f20

Please sign in to comment.