Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sample for 3.3.0 beta.1 #1008

Merged
merged 32 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5bb9bfc
update sample
chickenlj Sep 4, 2023
ed53700
update native sample
chickenlj Sep 4, 2023
a64b3cc
add mvnw
chickenlj Sep 5, 2023
a9c4fff
refactor native sample
chickenlj Sep 5, 2023
e662ec7
refactor native sample
chickenlj Sep 5, 2023
d6e878e
add missing files
chickenlj Sep 5, 2023
37218cd
update dockerfile
chickenlj Sep 5, 2023
cbdd855
add README.md
chickenlj Sep 5, 2023
2d64ca1
Update README.md
chickenlj Sep 5, 2023
aae5a26
Update README.md
chickenlj Sep 5, 2023
e725b20
update native sample
chickenlj Sep 6, 2023
a08d62b
Merge remote-tracking branch 'chickenlj/3.3.0-beta.1' into 3.3.0-beta.1
chickenlj Sep 6, 2023
47bca43
add native sample with registry
chickenlj Sep 6, 2023
2fa524c
update native sample
chickenlj Sep 7, 2023
753ca72
update
chickenlj Sep 7, 2023
b72107f
update
chickenlj Sep 7, 2023
2765e56
update
chickenlj Sep 7, 2023
0c92c93
update
chickenlj Sep 7, 2023
76c1a8d
update
chickenlj Sep 7, 2023
6cd2de0
force update maven dependency
chickenlj Sep 7, 2023
44fbe01
update native sample
chickenlj Sep 12, 2023
095fd5b
update configuration
chickenlj Sep 12, 2023
d6a11e6
exclude dependency
chickenlj Sep 12, 2023
34dd488
udpate sample
chickenlj Sep 12, 2023
6ddc159
update samples
chickenlj Oct 24, 2023
74a25dd
Merge branch 'master' into 3.3.0-beta.1
chickenlj Oct 24, 2023
c860a12
ignore license check for Dockerfile
chickenlj Oct 24, 2023
3be5f20
update sample
chickenlj Oct 24, 2023
1202d35
update test configuration
chickenlj Oct 25, 2023
ad0afb2
fix package
chickenlj Oct 25, 2023
0be5dce
fix ut
chickenlj Oct 25, 2023
2644122
fix ut
chickenlj Oct 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ header:
- '**/dubbo-samples-tengine/dubbo-samples-tengine-provider/src/main/resources/docker/sources.list'
- '**/.run/**'
- '**/*.js'
- '**/Dockerfile'
- '**/Dockerfile.jvm'

comment: on-failure

Expand Down
35 changes: 30 additions & 5 deletions 1-basic/dubbo-samples-api/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
# 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.

## Start the service provider
Follow steps below to run this example.

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

```bash
mvn clean package
mvn -Djava.net.preferIPv4Stack=true -Dexec.mainClass=org.apache.dubbo.samples.provider.Application exec:java
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:
* Standard HTTP tools like cURL.
* Dubbo sdk client.

### cURL
```shell
curl \
--header "Content-Type: application/json" \
--data '["Dubbo"]' \
http://localhost:50052/org.apache.dubbo.samples.api.GreetingsService/sayHi/
```

## Invoke the service consumer
### SDK client

```bash
mvn -Djava.net.preferIPv4Stack=true -Dexec.mainClass=org.apache.dubbo.samples.client.Application exec:java
mvn -Dexec.mainClass=org.apache.dubbo.samples.client.Application exec:java
```
2 changes: 1 addition & 1 deletion 1-basic/dubbo-samples-api/case-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ from: app-external-zookeeper.yml
props:
project_name: dubbo-samples-api
main_class: org.apache.dubbo.samples.provider.Application
dubbo_port: 20880
dubbo_port: 50052
check_log: "DubboBootstrap awaiting ..."
2 changes: 1 addition & 1 deletion 1-basic/dubbo-samples-api/case-versions.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@
# Supported component versions of the test case

# Spring app
dubbo.version=3.*
dubbo.version=3.3.1.*
java.version= [ >= 8 ]
9 changes: 1 addition & 8 deletions 1-basic/dubbo-samples-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<description>Dubbo Samples Api</description>

<properties>
<dubbo.version>3.2.6</dubbo.version>
<dubbo.version>3.3.0-beta.1</dubbo.version>
<junit5.version>5.9.2</junit5.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Expand All @@ -49,13 +49,6 @@
<version>${dubbo.version}</version>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,23 @@

import java.io.IOException;

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;

public class Application {
private static final String ZOOKEEPER_HOST = System.getProperty("zookeeper.address", "127.0.0.1");
private static final String ZOOKEEPER_PORT = System.getProperty("zookeeper.port", "2181");
private static final String ZOOKEEPER_ADDRESS = "zookeeper://" + ZOOKEEPER_HOST + ":" + ZOOKEEPER_PORT;

public static void main(String[] args) throws IOException {
ApplicationConfig applicationConfig = new ApplicationConfig("first-dubbo-consumer");
applicationConfig.setQosPort(22222);

ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
reference.setInterface(GreetingsService.class);

DubboBootstrap.getInstance()
.application(applicationConfig)
.registry(new RegistryConfig(ZOOKEEPER_ADDRESS))
.reference(reference)
.start();

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");

System.out.println("Receive result ======> " + message);
System.in.read();
System.exit(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.dubbo.samples.client;

import java.io.IOException;
import java.util.Date;

import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.samples.api.GreetingsService;

public class InfiniteLoopingApplication {
public static void main(String[] args) throws IOException {
ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
reference.setInterface(GreetingsService.class);
reference.setUrl("tri://localhost:50052");

DubboBootstrap.getInstance()
.application("first-dubbo-consumer")
.reference(reference)
.start();

GreetingsService service = reference.get();
while (true) {
try {
String message = service.sayHi("dubbo");
System.out.println(new Date() + " Receive result ======> " + message);
Thread.sleep(1000);
} catch (Throwable t) {
t.printStackTrace();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,16 @@

package org.apache.dubbo.samples.provider;

import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.bootstrap.DubboBootstrap;
import org.apache.dubbo.config.bootstrap.builders.ProtocolBuilder;
import org.apache.dubbo.config.bootstrap.builders.ServiceBuilder;
import org.apache.dubbo.samples.api.GreetingsService;

public class Application {
private static final String ZOOKEEPER_HOST = System.getProperty("zookeeper.address", "127.0.0.1");
private static final String ZOOKEEPER_PORT = System.getProperty("zookeeper.port", "2181");
private static final String ZOOKEEPER_ADDRESS = "zookeeper://" + ZOOKEEPER_HOST + ":" + ZOOKEEPER_PORT;

public static void main(String[] args) {
ApplicationConfig applicationConfig = new ApplicationConfig("first-dubbo-provider");
applicationConfig.setQosPort(33333);

ServiceConfig<GreetingsService> service = new ServiceConfig<>();
service.setInterface(GreetingsService.class);
service.setRef(new GreetingsServiceImpl());

DubboBootstrap.getInstance()
.application(applicationConfig)
.registry(new RegistryConfig(ZOOKEEPER_ADDRESS))
.protocol(new ProtocolConfig("dubbo", -1))
.service(service)
.protocol(ProtocolBuilder.newBuilder().name("tri").port(50052).build())
.service(ServiceBuilder.newBuilder().interfaceClass(GreetingsService.class).ref(new GreetingsServiceImpl()).build())
.start()
.await();
}
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
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 All @@ -8,7 +8,7 @@ More usages of Triple protocol can be found here:
* [Streaming RPCs](../../2-advanced/dubbo-samples-triple-streaming/)
* [Interoperability with standard gRPC clients and servers](../../2-advanced/dubbo-samples-triple-grpc/)
* [Triple without Protobuf (no IDL mode)](../../2-advanced/dubbo-samples-triple-no-idl/)
* [Using triple with other languages and browser](https://dubbo.apache.org/zh-cn/overview/quickstart/rpc/)
* [Using triple with other languages and browser](https://dubbo.apache.org/zh-cn/overview/mannual/)

## Run The Demo
Detailed explanation of this demo can be found [here](https://dubbo.apache.org/zh-cn/overview/quickstart/rpc/java/).
Expand All @@ -34,7 +34,7 @@ There are two ways to test the server works as expected:
```shell
curl \
--header "Content-Type: application/json" \
--data '[{"name": "Dubbo"}]' \
--data '{"name": "Dubbo"}' \
http://localhost:50052/org.apache.dubbo.samples.tri.unary.Greeter/greet/
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>dubbo-samples-triple-unary</artifactId>
<artifactId>dubbo-samples-idl</artifactId>

<properties>
<dubbo.version>3.2.6</dubbo.version>
<dubbo.version>3.3.0-beta.1</dubbo.version>
<source.level>1.8</source.level>
<target.level>1.8</target.level>
<grpc.version>1.54.1</grpc.version>
Expand All @@ -49,6 +49,11 @@
<artifactId>protobuf-java</artifactId>
<version>3.19.6</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.19.6</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
Expand Down
36 changes: 36 additions & 0 deletions 1-basic/dubbo-samples-spring-boot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,40 @@ This example shows how to use Dubbo Spring Boot Starter to develop Dubbo applica
* provider, implements Dubbo service
* consumer, consumes Dubbo service

## Install dependencies
Step into 'dubbo-samples-spring-boot' directory, run the following command:

```shell
$ mvn clean install
```

## Start provider
Enter provider directory:
```shell
$ cd dubbo-samples-spring-boot-provider
```

then, run the following command to start provider:
```shell
$ mvn compile exec:java -Dexec.mainClass="org.apache.dubbo.springboot.demo.provider.ProviderApplication"
```

Run the following command to see server works as expected:
```shell
curl \
--header "Content-Type: application/json" \
--data '["Dubbo"]' \
http://localhost:50052/org.apache.dubbo.springboot.demo.DemoService/sayHello/
```

## Start consumer
Enter provider directory:
```shell
$ cd dubbo-samples-spring-boot-consumer
```

then, run the following command to start consumer:
```shell
$ mvn compile exec:java -Dexec.mainClass="org.apache.dubbo.springboot.demo.consumer.ConsumerApplication"
```

4 changes: 2 additions & 2 deletions 1-basic/dubbo-samples-spring-boot/case-configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
waitPortsBeforeRun:
- zookeeper:2181
checkPorts:
- 20880
- 50052
checkLog: "Current Spring Boot Application is await..."

test:
Expand All @@ -39,6 +39,6 @@ services:
- zookeeper.address=zookeeper
waitPortsBeforeRun:
- zookeeper:2181
- provider:20880
- provider:50052
depends_on:
- provider
2 changes: 1 addition & 1 deletion 1-basic/dubbo-samples-spring-boot/case-versions.conf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
# Supported component versions of the test case

# Spring app
dubbo.version=3.*
dubbo.version=3.3.1.*
spring.version=4.*, 5.*
java.version= [>= 8]
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,7 @@
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper-curator5</artifactId>
<type>pom</type>
<exclusions>
<exclusion>
<artifactId>slf4j-reload4j</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
<artifactId>dubbo-zookeeper-curator5-spring-boot-starter</artifactId>
</dependency>

<!-- spring starter -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,5 @@
dubbo:
application:
name: dubbo-springboot-demo-consumer
protocol:
name: dubbo
port: -1
registry:
address: zookeeper://${zookeeper.address:127.0.0.1}:2181
Loading
Loading