diff --git a/.licenserc.yaml b/.licenserc.yaml index fe597fb970..1da5666ce1 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -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 diff --git a/1-basic/dubbo-samples-api/README.md b/1-basic/dubbo-samples-api/README.md index 965d6ea4a8..7154bcca88 100644 --- a/1-basic/dubbo-samples-api/README.md +++ b/1-basic/dubbo-samples-api/README.md @@ -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 ``` diff --git a/1-basic/dubbo-samples-api/case-configuration.yml b/1-basic/dubbo-samples-api/case-configuration.yml index b846574269..f37a57acb4 100644 --- a/1-basic/dubbo-samples-api/case-configuration.yml +++ b/1-basic/dubbo-samples-api/case-configuration.yml @@ -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 ..." diff --git a/1-basic/dubbo-samples-api/case-versions.conf b/1-basic/dubbo-samples-api/case-versions.conf index 5610cf334a..1ddc1620c2 100644 --- a/1-basic/dubbo-samples-api/case-versions.conf +++ b/1-basic/dubbo-samples-api/case-versions.conf @@ -20,5 +20,5 @@ # Supported component versions of the test case # Spring app -dubbo.version=3.* +dubbo.version=3.3.1.* java.version= [ >= 8 ] \ No newline at end of file diff --git a/1-basic/dubbo-samples-api/pom.xml b/1-basic/dubbo-samples-api/pom.xml index efadba9eec..be3f43eafa 100644 --- a/1-basic/dubbo-samples-api/pom.xml +++ b/1-basic/dubbo-samples-api/pom.xml @@ -36,7 +36,7 @@ Dubbo Samples Api - 3.2.6 + 3.3.0-beta.1 5.9.2 1.8 1.8 @@ -49,13 +49,6 @@ ${dubbo.version} - - org.apache.dubbo - dubbo-dependencies-zookeeper-curator5 - ${dubbo.version} - pom - - org.junit.jupiter junit-jupiter-engine diff --git a/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/Application.java b/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/Application.java index 73e551f549..28354bccd4 100644 --- a/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/Application.java +++ b/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/Application.java @@ -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 reference = new ReferenceConfig<>(); - reference.setInterface(GreetingsService.class); - - DubboBootstrap.getInstance() - .application(applicationConfig) - .registry(new RegistryConfig(ZOOKEEPER_ADDRESS)) - .reference(reference) - .start(); - + ReferenceConfig reference = + ReferenceBuilder.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); diff --git a/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/InfiniteLoopingApplication.java b/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/InfiniteLoopingApplication.java new file mode 100644 index 0000000000..e94ddffa65 --- /dev/null +++ b/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/InfiniteLoopingApplication.java @@ -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 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(); + } + } + } + +} diff --git a/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/Application.java b/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/Application.java index 7d0b3d0c5a..4018c11bc1 100644 --- a/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/Application.java +++ b/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/Application.java @@ -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 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(); } diff --git a/1-basic/dubbo-samples-api/src/test/java/org/apache/dubbo/samples/client/GreetingServiceIT.java b/1-basic/dubbo-samples-api/src/test/java/org/apache/dubbo/samples/client/GreetingServiceIT.java index a29ea5d0be..050571559b 100644 --- a/1-basic/dubbo-samples-api/src/test/java/org/apache/dubbo/samples/client/GreetingServiceIT.java +++ b/1-basic/dubbo-samples-api/src/test/java/org/apache/dubbo/samples/client/GreetingServiceIT.java @@ -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 reference = new ReferenceConfig<>(); - reference.setApplication(new ApplicationConfig("first-dubbo-consumer")); - reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181")); - reference.setInterface(GreetingsService.class); + ReferenceConfig reference = + ReferenceBuilder.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"); } diff --git a/1-basic/dubbo-samples-triple-unary/README.md b/1-basic/dubbo-samples-idl/README.md similarity index 94% rename from 1-basic/dubbo-samples-triple-unary/README.md rename to 1-basic/dubbo-samples-idl/README.md index 4aa30b8eef..d87ae9f5fd 100644 --- a/1-basic/dubbo-samples-triple-unary/README.md +++ b/1-basic/dubbo-samples-idl/README.md @@ -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. @@ -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/). @@ -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/ ``` diff --git a/1-basic/dubbo-samples-triple-unary/pom.xml b/1-basic/dubbo-samples-idl/pom.xml similarity index 94% rename from 1-basic/dubbo-samples-triple-unary/pom.xml rename to 1-basic/dubbo-samples-idl/pom.xml index fb33611352..ff18dff840 100644 --- a/1-basic/dubbo-samples-triple-unary/pom.xml +++ b/1-basic/dubbo-samples-idl/pom.xml @@ -26,10 +26,10 @@ 4.0.0 - dubbo-samples-triple-unary + dubbo-samples-idl - 3.2.6 + 3.3.0-beta.1 1.8 1.8 1.54.1 @@ -49,6 +49,11 @@ protobuf-java 3.19.6 + + com.google.protobuf + protobuf-java-util + 3.19.6 + org.apache.dubbo dubbo-dependencies-zookeeper-curator5 diff --git a/1-basic/dubbo-samples-triple-unary/src/main/java/org/apache/dubbo/samples/tri/unary/GreeterImpl.java b/1-basic/dubbo-samples-idl/src/main/java/org/apache/dubbo/samples/tri/unary/GreeterImpl.java similarity index 100% rename from 1-basic/dubbo-samples-triple-unary/src/main/java/org/apache/dubbo/samples/tri/unary/GreeterImpl.java rename to 1-basic/dubbo-samples-idl/src/main/java/org/apache/dubbo/samples/tri/unary/GreeterImpl.java diff --git a/1-basic/dubbo-samples-triple-unary/src/main/java/org/apache/dubbo/samples/tri/unary/TriUnaryClient.java b/1-basic/dubbo-samples-idl/src/main/java/org/apache/dubbo/samples/tri/unary/TriUnaryClient.java similarity index 100% rename from 1-basic/dubbo-samples-triple-unary/src/main/java/org/apache/dubbo/samples/tri/unary/TriUnaryClient.java rename to 1-basic/dubbo-samples-idl/src/main/java/org/apache/dubbo/samples/tri/unary/TriUnaryClient.java diff --git a/1-basic/dubbo-samples-triple-unary/src/main/java/org/apache/dubbo/samples/tri/unary/TriUnaryServer.java b/1-basic/dubbo-samples-idl/src/main/java/org/apache/dubbo/samples/tri/unary/TriUnaryServer.java similarity index 100% rename from 1-basic/dubbo-samples-triple-unary/src/main/java/org/apache/dubbo/samples/tri/unary/TriUnaryServer.java rename to 1-basic/dubbo-samples-idl/src/main/java/org/apache/dubbo/samples/tri/unary/TriUnaryServer.java diff --git a/1-basic/dubbo-samples-triple-unary/src/main/java/org/apache/dubbo/samples/tri/unary/util/EmbeddedZooKeeper.java b/1-basic/dubbo-samples-idl/src/main/java/org/apache/dubbo/samples/tri/unary/util/EmbeddedZooKeeper.java similarity index 100% rename from 1-basic/dubbo-samples-triple-unary/src/main/java/org/apache/dubbo/samples/tri/unary/util/EmbeddedZooKeeper.java rename to 1-basic/dubbo-samples-idl/src/main/java/org/apache/dubbo/samples/tri/unary/util/EmbeddedZooKeeper.java diff --git a/1-basic/dubbo-samples-triple-unary/src/main/java/org/apache/dubbo/samples/tri/unary/util/TriSampleConstants.java b/1-basic/dubbo-samples-idl/src/main/java/org/apache/dubbo/samples/tri/unary/util/TriSampleConstants.java similarity index 100% rename from 1-basic/dubbo-samples-triple-unary/src/main/java/org/apache/dubbo/samples/tri/unary/util/TriSampleConstants.java rename to 1-basic/dubbo-samples-idl/src/main/java/org/apache/dubbo/samples/tri/unary/util/TriSampleConstants.java diff --git a/1-basic/dubbo-samples-triple-unary/src/main/proto/greeter.proto b/1-basic/dubbo-samples-idl/src/main/proto/greeter.proto similarity index 100% rename from 1-basic/dubbo-samples-triple-unary/src/main/proto/greeter.proto rename to 1-basic/dubbo-samples-idl/src/main/proto/greeter.proto diff --git a/1-basic/dubbo-samples-triple-unary/src/main/resources/log4j.properties b/1-basic/dubbo-samples-idl/src/main/resources/log4j.properties similarity index 100% rename from 1-basic/dubbo-samples-triple-unary/src/main/resources/log4j.properties rename to 1-basic/dubbo-samples-idl/src/main/resources/log4j.properties diff --git a/1-basic/dubbo-samples-spring-boot/README.md b/1-basic/dubbo-samples-spring-boot/README.md index 5b46528f4e..6adc928b7d 100644 --- a/1-basic/dubbo-samples-spring-boot/README.md +++ b/1-basic/dubbo-samples-spring-boot/README.md @@ -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" +``` diff --git a/1-basic/dubbo-samples-spring-boot/case-configuration.yml b/1-basic/dubbo-samples-spring-boot/case-configuration.yml index c4d3a82295..b1721bc045 100644 --- a/1-basic/dubbo-samples-spring-boot/case-configuration.yml +++ b/1-basic/dubbo-samples-spring-boot/case-configuration.yml @@ -27,7 +27,7 @@ services: waitPortsBeforeRun: - zookeeper:2181 checkPorts: - - 20880 + - 50052 checkLog: "Current Spring Boot Application is await..." test: @@ -39,6 +39,6 @@ services: - zookeeper.address=zookeeper waitPortsBeforeRun: - zookeeper:2181 - - provider:20880 + - provider:50052 depends_on: - provider diff --git a/1-basic/dubbo-samples-spring-boot/case-versions.conf b/1-basic/dubbo-samples-spring-boot/case-versions.conf index b03fb1ae45..cb67971615 100644 --- a/1-basic/dubbo-samples-spring-boot/case-versions.conf +++ b/1-basic/dubbo-samples-spring-boot/case-versions.conf @@ -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] diff --git a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-consumer/pom.xml b/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-consumer/pom.xml index 6da57162ea..a339a0730f 100644 --- a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-consumer/pom.xml +++ b/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-consumer/pom.xml @@ -40,14 +40,7 @@ org.apache.dubbo - dubbo-dependencies-zookeeper-curator5 - pom - - - slf4j-reload4j - org.slf4j - - + dubbo-zookeeper-curator5-spring-boot-starter diff --git a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-consumer/src/main/resources/application.yml b/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-consumer/src/main/resources/application.yml index 9a7a8fe1fb..631228afe0 100644 --- a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-consumer/src/main/resources/application.yml +++ b/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-consumer/src/main/resources/application.yml @@ -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 diff --git a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml b/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml index d0093ad1d8..3d49447d78 100644 --- a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml +++ b/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/pom.xml @@ -41,14 +41,7 @@ org.apache.dubbo - dubbo-dependencies-zookeeper-curator5 - pom - - - slf4j-reload4j - org.slf4j - - + dubbo-zookeeper-curator5-spring-boot-starter diff --git a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/src/main/resources/application.yml b/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/src/main/resources/application.yml index 9af8aee587..f103643047 100644 --- a/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/src/main/resources/application.yml +++ b/1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-provider/src/main/resources/application.yml @@ -18,7 +18,7 @@ dubbo: application: name: dubbo-springboot-demo-provider protocol: - name: dubbo - port: -1 + name: tri + port: 50052 registry: address: zookeeper://${zookeeper.address:127.0.0.1}:2181 \ No newline at end of file diff --git a/1-basic/dubbo-samples-spring-boot/pom.xml b/1-basic/dubbo-samples-spring-boot/pom.xml index 47d22bf805..bbfd5f3694 100644 --- a/1-basic/dubbo-samples-spring-boot/pom.xml +++ b/1-basic/dubbo-samples-spring-boot/pom.xml @@ -37,7 +37,7 @@ Dubbo Samples Spring Boot - 3.2.6 + 3.3.0-beta.1 4.13.1 2.7.8 1.8 @@ -71,13 +71,6 @@ import - - org.apache.dubbo - dubbo-dependencies-zookeeper-curator5 - ${dubbo.version} - pom - - junit junit diff --git a/1-basic/pom.xml b/1-basic/pom.xml index c0d86f8ae5..66f57eff89 100644 --- a/1-basic/pom.xml +++ b/1-basic/pom.xml @@ -27,11 +27,8 @@ Dubbo Basic Usage Samples - dubbo-samples-annotation dubbo-samples-api - dubbo-samples-spring-xml dubbo-samples-spring-boot - dubbo-samples-triple-unary - dubbo-samples-native-image + dubbo-samples-idl \ No newline at end of file diff --git a/10-task/dubbo-samples-shop/deploy/All.yml b/10-task/dubbo-samples-shop/deploy/All.yml index 84d04052b5..33e0c02127 100644 --- a/10-task/dubbo-samples-shop/deploy/All.yml +++ b/10-task/dubbo-samples-shop/deploy/All.yml @@ -117,7 +117,7 @@ spec: app: dubbo-admin spec: containers: - - image: apache/dubbo-admin:0.5.0 + - image: apache/dubbo-admin:0.6.0 name: dubbo-admin ports: - containerPort: 38080 diff --git a/1-basic/dubbo-samples-annotation/README.md b/2-advanced/dubbo-samples-annotation/README.md similarity index 100% rename from 1-basic/dubbo-samples-annotation/README.md rename to 2-advanced/dubbo-samples-annotation/README.md diff --git a/1-basic/dubbo-samples-annotation/case-configuration.yml b/2-advanced/dubbo-samples-annotation/case-configuration.yml similarity index 100% rename from 1-basic/dubbo-samples-annotation/case-configuration.yml rename to 2-advanced/dubbo-samples-annotation/case-configuration.yml diff --git a/1-basic/dubbo-samples-annotation/case-versions.conf b/2-advanced/dubbo-samples-annotation/case-versions.conf similarity index 100% rename from 1-basic/dubbo-samples-annotation/case-versions.conf rename to 2-advanced/dubbo-samples-annotation/case-versions.conf diff --git a/1-basic/dubbo-samples-annotation/pom.xml b/2-advanced/dubbo-samples-annotation/pom.xml similarity index 100% rename from 1-basic/dubbo-samples-annotation/pom.xml rename to 2-advanced/dubbo-samples-annotation/pom.xml diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConstants.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConstants.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConstants.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConstants.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConsumerBootstrap.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConsumerBootstrap.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConsumerBootstrap.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationConsumerBootstrap.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationProviderBootstrap.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationProviderBootstrap.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationProviderBootstrap.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/AnnotationProviderBootstrap.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/EmbeddedZooKeeper.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/EmbeddedZooKeeper.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/EmbeddedZooKeeper.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/EmbeddedZooKeeper.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/action/AnnotationAction.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/action/AnnotationAction.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/action/AnnotationAction.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/action/AnnotationAction.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/GreetingService.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/GreetingService.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/GreetingService.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/GreetingService.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/HelloService.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/HelloService.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/HelloService.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/HelloService.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/Notify.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/Notify.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/Notify.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/api/Notify.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/config/ConsumerConfiguration.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/config/ConsumerConfiguration.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/config/ConsumerConfiguration.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/config/ConsumerConfiguration.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/config/ProviderConfiguration.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/config/ProviderConfiguration.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/config/ProviderConfiguration.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/config/ProviderConfiguration.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationGreetingServiceImpl.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationGreetingServiceImpl.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationGreetingServiceImpl.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationGreetingServiceImpl.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationHelloServiceImpl.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationHelloServiceImpl.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationHelloServiceImpl.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/AnnotationHelloServiceImpl.java diff --git a/1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/NotifyImpl.java b/2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/NotifyImpl.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/NotifyImpl.java rename to 2-advanced/dubbo-samples-annotation/src/main/java/org/apache/dubbo/samples/annotation/impl/NotifyImpl.java diff --git a/1-basic/dubbo-samples-annotation/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-annotation/src/main/resources/log4j.properties similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/resources/log4j.properties rename to 2-advanced/dubbo-samples-annotation/src/main/resources/log4j.properties diff --git a/1-basic/dubbo-samples-annotation/src/main/resources/spring/dubbo-consumer.properties b/2-advanced/dubbo-samples-annotation/src/main/resources/spring/dubbo-consumer.properties similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/resources/spring/dubbo-consumer.properties rename to 2-advanced/dubbo-samples-annotation/src/main/resources/spring/dubbo-consumer.properties diff --git a/1-basic/dubbo-samples-annotation/src/main/resources/spring/dubbo-provider.properties b/2-advanced/dubbo-samples-annotation/src/main/resources/spring/dubbo-provider.properties similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/main/resources/spring/dubbo-provider.properties rename to 2-advanced/dubbo-samples-annotation/src/main/resources/spring/dubbo-provider.properties diff --git a/1-basic/dubbo-samples-annotation/src/test/java/org/apache/dubbo/samples/annotation/AnnotationServicesIT.java b/2-advanced/dubbo-samples-annotation/src/test/java/org/apache/dubbo/samples/annotation/AnnotationServicesIT.java similarity index 100% rename from 1-basic/dubbo-samples-annotation/src/test/java/org/apache/dubbo/samples/annotation/AnnotationServicesIT.java rename to 2-advanced/dubbo-samples-annotation/src/test/java/org/apache/dubbo/samples/annotation/AnnotationServicesIT.java diff --git a/2-advanced/dubbo-samples-api-with-registry/README.md b/2-advanced/dubbo-samples-api-with-registry/README.md new file mode 100644 index 0000000000..5deeb82de0 --- /dev/null +++ b/2-advanced/dubbo-samples-api-with-registry/README.md @@ -0,0 +1,16 @@ +# 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`. + +## Start the service provider + +```bash +mvn clean package +mvn -Djava.net.preferIPv4Stack=true -Dexec.mainClass=org.apache.dubbo.samples.api.provider.Application exec:java +``` + +## Invoke the service consumer + +```bash +mvn -Djava.net.preferIPv4Stack=true -Dexec.mainClass=org.apache.dubbo.samples.api.client.Application exec:java +``` diff --git a/2-advanced/dubbo-samples-api-with-registry/case-configuration.yml b/2-advanced/dubbo-samples-api-with-registry/case-configuration.yml new file mode 100644 index 0000000000..ecdf913b4a --- /dev/null +++ b/2-advanced/dubbo-samples-api-with-registry/case-configuration.yml @@ -0,0 +1,23 @@ +# 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. + +from: app-external-zookeeper.yml + +props: + project_name: dubbo-samples-api + main_class: org.apache.dubbo.samples.api.provider.Application + dubbo_port: 20880 + check_log: "DubboBootstrap awaiting ..." diff --git a/2-advanced/dubbo-samples-api-with-registry/case-versions.conf b/2-advanced/dubbo-samples-api-with-registry/case-versions.conf new file mode 100644 index 0000000000..5610cf334a --- /dev/null +++ b/2-advanced/dubbo-samples-api-with-registry/case-versions.conf @@ -0,0 +1,24 @@ +# +# +# 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. +# + + +# Supported component versions of the test case + +# Spring app +dubbo.version=3.* +java.version= [ >= 8 ] \ No newline at end of file diff --git a/2-advanced/dubbo-samples-api-with-registry/pom.xml b/2-advanced/dubbo-samples-api-with-registry/pom.xml new file mode 100644 index 0000000000..e0bb44e8d2 --- /dev/null +++ b/2-advanced/dubbo-samples-api-with-registry/pom.xml @@ -0,0 +1,78 @@ + + + + + + org.apache + apache + 23 + + + + org.apache.dubbo + 1.0-SNAPSHOT + + 4.0.0 + + dubbo-samples-api-with-registry + Dubbo Samples Api With Registry + Dubbo Samples Api with registry and application + + + 3.2.6 + 5.9.2 + 1.8 + 1.8 + + + + + org.apache.dubbo + dubbo + ${dubbo.version} + + + + org.apache.dubbo + dubbo-dependencies-zookeeper-curator5 + ${dubbo.version} + pom + + + + org.junit.jupiter + junit-jupiter-engine + ${junit5.version} + test + + + org.junit.jupiter + junit-jupiter-api + ${junit5.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit5.version} + test + + + diff --git a/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/api/GreetingsService.java b/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/api/GreetingsService.java new file mode 100644 index 0000000000..f249798887 --- /dev/null +++ b/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/api/GreetingsService.java @@ -0,0 +1,22 @@ +/* + * 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.api.api; + +public interface GreetingsService { + String sayHi(String name); +} diff --git a/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/AlwaysApplication.java b/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/client/AlwaysApplication.java similarity index 86% rename from 1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/AlwaysApplication.java rename to 2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/client/AlwaysApplication.java index b54e37541a..3bca3d9681 100644 --- a/1-basic/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/AlwaysApplication.java +++ b/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/client/AlwaysApplication.java @@ -15,16 +15,15 @@ * limitations under the License. */ -package org.apache.dubbo.samples.client; +package org.apache.dubbo.samples.api.client; import java.io.IOException; import java.util.Date; -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.samples.api.GreetingsService; +import org.apache.dubbo.samples.api.api.GreetingsService; public class AlwaysApplication { private static final String ZOOKEEPER_HOST = System.getProperty("zookeeper.address", "127.0.0.1"); @@ -32,14 +31,11 @@ public class AlwaysApplication { 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 reference = new ReferenceConfig<>(); reference.setInterface(GreetingsService.class); DubboBootstrap.getInstance() - .application(applicationConfig) + .application("first-dubbo-consumer") .registry(new RegistryConfig(ZOOKEEPER_ADDRESS)) .reference(reference) .start(); diff --git a/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/client/Application.java b/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/client/Application.java new file mode 100644 index 0000000000..5509994955 --- /dev/null +++ b/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/client/Application.java @@ -0,0 +1,49 @@ +/* + * 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.api.client; + +import java.io.IOException; + +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.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 { + ReferenceConfig reference = new ReferenceConfig<>(); + reference.setInterface(GreetingsService.class); + + DubboBootstrap.getInstance() + .application("first-dubbo-consumer") + .registry(new RegistryConfig(ZOOKEEPER_ADDRESS)) + .reference(reference) + .start(); + + GreetingsService service = reference.get(); + String message = service.sayHi("dubbo"); + System.out.println("Receive result ======> " + message); + System.in.read(); + System.exit(0); + } + +} diff --git a/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/provider/Application.java b/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/provider/Application.java new file mode 100644 index 0000000000..8214e9eb77 --- /dev/null +++ b/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/provider/Application.java @@ -0,0 +1,45 @@ +/* + * 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.api.provider; + +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.samples.api.api.GreetingsService; +import org.apache.dubbo.samples.api.provider.GreetingsServiceImpl; + +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) { + ServiceConfig service = new ServiceConfig<>(); + service.setInterface(GreetingsService.class); + service.setRef(new GreetingsServiceImpl()); + + DubboBootstrap.getInstance() + .application("first-dubbo-provider") + .registry(new RegistryConfig(ZOOKEEPER_ADDRESS)) + .protocol(new ProtocolConfig("dubbo", -1)) + .service(service) + .start() + .await(); + } +} diff --git a/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/provider/GreetingsServiceImpl.java b/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/provider/GreetingsServiceImpl.java new file mode 100644 index 0000000000..d0a92a919d --- /dev/null +++ b/2-advanced/dubbo-samples-api-with-registry/src/main/java/org/apache/dubbo/samples/api/provider/GreetingsServiceImpl.java @@ -0,0 +1,27 @@ +/* + * 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.api.provider; + +import org.apache.dubbo.samples.api.api.GreetingsService; + +public class GreetingsServiceImpl implements GreetingsService { + @Override + public String sayHi(String name) { + return "hi, " + name; + } +} diff --git a/2-advanced/dubbo-samples-api-with-registry/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-api-with-registry/src/main/resources/log4j.properties new file mode 100644 index 0000000000..e976f5c2b4 --- /dev/null +++ b/2-advanced/dubbo-samples-api-with-registry/src/main/resources/log4j.properties @@ -0,0 +1,25 @@ +# +# +# 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. +# +# +###set log levels### +log4j.rootLogger=info, stdout +###output to the console### +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=[%d{dd/MM/yy hh:mm:ss:sss z}] %t %5p %c{2}: %m%n \ No newline at end of file diff --git a/2-advanced/dubbo-samples-api-with-registry/src/test/java/org/apache/dubbo/samples/api/client/GreetingServiceIT.java b/2-advanced/dubbo-samples-api-with-registry/src/test/java/org/apache/dubbo/samples/api/client/GreetingServiceIT.java new file mode 100644 index 0000000000..78c37e497f --- /dev/null +++ b/2-advanced/dubbo-samples-api-with-registry/src/test/java/org/apache/dubbo/samples/api/client/GreetingServiceIT.java @@ -0,0 +1,40 @@ +/* + * 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.api.client; + +import org.apache.dubbo.config.ApplicationConfig; +import org.apache.dubbo.config.ReferenceConfig; +import org.apache.dubbo.config.RegistryConfig; +import org.apache.dubbo.samples.api.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 reference = new ReferenceConfig<>(); + reference.setApplication(new ApplicationConfig("first-dubbo-consumer")); + reference.setRegistry(new RegistryConfig("zookeeper://" + zookeeperHost + ":2181")); + reference.setInterface(GreetingsService.class); + GreetingsService service = reference.get(); + String message = service.sayHi("dubbo"); + Assertions.assertEquals(message, "hi, dubbo"); + } +} diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/.mvn/wrapper/maven-wrapper.properties b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/.mvn/wrapper/maven-wrapper.properties new file mode 100755 index 0000000000..ca5ab4bab1 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# 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 +# +# https://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. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/Dockerfile b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/Dockerfile new file mode 100644 index 0000000000..c805d98e9b --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/Dockerfile @@ -0,0 +1,22 @@ +# Using Oracle GraalVM for JDK 17 Community Edition +FROM ghcr.io/graalvm/native-image-community:17-ol8 AS builder + +# Set the working directory to /home/app +WORKDIR /build + +# Copy the source code into the image for building +COPY . /build + +ARG APP_FILE + +# Build +RUN ./mvnw clean package --no-transfer-progress native:compile -Pnative + +# The deployment Image +FROM container-registry.oracle.com/os/oraclelinux:9-slim + +EXPOSE 9091 + +# Copy the native executable into the containers +COPY --from=builder /build/target/dubbo-samples-native-image-registry-consumer app +ENTRYPOINT ["/app"] \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/Dockerfile.jvm b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/Dockerfile.jvm new file mode 100644 index 0000000000..5110a19e86 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/Dockerfile.jvm @@ -0,0 +1,19 @@ +# Using Oracle GraalVM for JDK 17 +FROM openjdk:17 + +# Set the working directory to /home/app +WORKDIR /build +COPY . /build + +RUN ./mvnw clean package + +# JAR file will be specified by passing in a build time argument to docker build +ARG APP_FILE + +EXPOSE 9091 + +# opy the JAR file into the root and rename +COPY ./target/${APP_FILE} app.jar + +# Run java with the jar file when the container starts up +CMD ["java","-jar","app.jar"] \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/README.md b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/README.md new file mode 100644 index 0000000000..735dab5bde --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/README.md @@ -0,0 +1,24 @@ +# Build native image +The following steps work for all platforms - MacOS, Windows, and Linux. + +To do this, we've provided a [multistage Docker build file](./Dockerfile) for building a Docker image containing your native executable inside a Docker container. + +## Build the consumer + +1. Containerise the native executable using the following command: + + ```shell + docker build -f ./Dockerfile --build-arg APP_FILE=dubbo-samples-native-image-consumer -t consumer-native:1.0.0 . + ``` + +2. Run the application: + + ```shell + docker run --rm --name native-consumer consumer-native:1.0.0 + ``` + +3. To stop the application, first get the container id using `docker ps`, and then run: + + ```shell + docker rm -f + ``` diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/mvnw b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/mvnw new file mode 100755 index 0000000000..b7f064624f --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/mvnw @@ -0,0 +1,287 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.1.1 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + printf '%s' "$(cd "$basedir"; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname $0)") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $wrapperUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + QUIET="--quiet" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + elif command -v curl > /dev/null; then + QUIET="--silent" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=`cygpath --path --windows "$javaSource"` + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/mvnw.cmd b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/mvnw.cmd new file mode 100644 index 0000000000..474c9d6b74 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/mvnw.cmd @@ -0,0 +1,187 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.1.1 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/pom.xml b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/pom.xml new file mode 100644 index 0000000000..2580c21cd7 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/pom.xml @@ -0,0 +1,257 @@ + + + + org.apache + apache + 23 + + + + 4.0.0 + org.apache.dubbo + 1.0-SNAPSHOT + dubbo-samples-native-image-registry-consumer + + + 17 + 17 + 17 + 5.1.0 + 3.3.0-beta.1 + 3.0.5 + 3.0.5 + 0.9.23 + + + + + + org.apache.dubbo + dubbo-bom + ${dubbo.version} + pom + import + + + + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + + org.springframework + spring-context + + + org.springframework + spring-beans + + + org.springframework + spring-web + + + org.springframework.boot + spring-boot-autoconfigure + + + org.apache.dubbo + dubbo-serialization-hessian2 + + + + + org.apache.dubbo + dubbo-zookeeper-curator5-spring-boot-starter + + + ch.qos.logback + logback-classic + + + ch.qos.logback + logback-core + + + org.slf4j + slf4j-log4j12 + + + org.slf4j + slf4j-api + + + log4j + log4j + + + com.fasterxml.jackson.core + jackson-databind + + + + + + org.apache.dubbo + dubbo-native + + + + org.apache.dubbo + dubbo-config-spring6 + + + + com.google.protobuf + protobuf-java + 3.19.6 + + + com.google.protobuf + protobuf-java-util + 3.19.6 + + + + org.springframework.boot + spring-boot-starter + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-starter-logging + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot.version} + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-maven-plugin.version} + + + + repackage + + + + + + + + + + native + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 17 + true + true + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-maven-plugin.version} + + + process-aot + + process-aot + + + + + + org.graalvm.buildtools + native-maven-plugin + ${native-maven-plugin.version} + + ${project.build.outputDirectory} + + true + + 22.3 + + + + add-reachability-metadata + + add-reachability-metadata + + + + + + org.apache.dubbo + dubbo-maven-plugin + ${dubbo.version} + + org.apache.dubbo.registry.consumer.NativeDemoConsumerRegistryApplication + + + + process-sources + + dubbo-process-aot + + + + + + + + + + + + apache.snapshots.https + Apache Development Snapshot Repository + https://repository.apache.org/content/repositories/snapshots + default + + false + + + true + daily + + + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/DemoService.java b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/DemoService.java new file mode 100644 index 0000000000..81b023dbd3 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/DemoService.java @@ -0,0 +1,29 @@ +/* + * 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.registry; + + +import java.util.concurrent.CompletableFuture; + +public interface DemoService { + + HelloResponse sayHello(HelloRequest request); + + default CompletableFuture sayHelloAsync(HelloRequest request) { + return CompletableFuture.completedFuture(sayHello(request)); + } +} diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/HelloRequest.java b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/HelloRequest.java new file mode 100644 index 0000000000..ac32b9e781 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/HelloRequest.java @@ -0,0 +1,40 @@ +/* + * 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.registry; + +import java.io.Serializable; + +public class HelloRequest implements Serializable { + private String name; + + public HelloRequest(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public String toString() { + return this.name; + } +} diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/HelloResponse.java b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/HelloResponse.java new file mode 100644 index 0000000000..d17d9efa12 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/HelloResponse.java @@ -0,0 +1,36 @@ +/* + * 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.registry; + + +import java.io.Serializable; + +public class HelloResponse implements Serializable { + private String response; + + public HelloResponse(String response) { + this.response = response; + } + + public String getResponse() { + return response; + } + + public void setResponse(String response) { + this.response = response; + } +} diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/consumer/NativeDemoConsumerRegistryApplication.java b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/consumer/NativeDemoConsumerRegistryApplication.java new file mode 100644 index 0000000000..839e95420c --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/consumer/NativeDemoConsumerRegistryApplication.java @@ -0,0 +1,56 @@ +/* + * 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.registry.consumer; + +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.apache.dubbo.registry.DemoService; +import org.apache.dubbo.registry.HelloRequest; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; + +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; + +@SpringBootApplication(scanBasePackages = {"org.apache.dubbo.registry"}) +@EnableDubbo(scanBasePackages = {"org.apache.dubbo.registry.consumer"}) +public class NativeDemoConsumerRegistryApplication { + + @DubboReference + private DemoService demoService; + + public static void main(String[] args) throws InterruptedException { + ConfigurableApplicationContext context = SpringApplication.run(NativeDemoConsumerRegistryApplication.class, args); + NativeDemoConsumerRegistryApplication application = context.getBean(NativeDemoConsumerRegistryApplication.class); + RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); + System.out.println("dubbo consumer application started, The time taken to start the application is " + + (System.currentTimeMillis() - runtimeMXBean.getStartTime()) +" ms"); + + long startCallTime = System.currentTimeMillis(); + String result = application.doSayHello("world"); + System.out.println("The time taken for the first call is " + + (System.currentTimeMillis() - startCallTime) +" ms"); + System.out.println("result: " + result); + } + + public String doSayHello(String name) { + return demoService.sayHello(new HelloRequest(name)).getResponse(); + } + +} diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/controller/WebController.java b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/controller/WebController.java new file mode 100755 index 0000000000..c7cd8b9d19 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/java/org/apache/dubbo/registry/controller/WebController.java @@ -0,0 +1,45 @@ +/* + * 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.registry.controller; + +import org.apache.dubbo.config.annotation.DubboReference; +import org.apache.dubbo.registry.DemoService; +import org.apache.dubbo.registry.HelloRequest; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.ModelAndView; + +@RestController +public class WebController { + @DubboReference + private DemoService demoService; + + public WebController() { + System.out.println("test"); + } + + // user GET to avoid resubmit warning on browser side. + @RequestMapping(value = "/dubbo-sae", method = RequestMethod.GET) + @ResponseBody + String test() { + return "Here is the response from provider: \"" + demoService.sayHello(new HelloRequest("sae")) + "\"."; + } +} \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/resources/application.yml new file mode 100644 index 0000000000..a2b6691b24 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/resources/application.yml @@ -0,0 +1,32 @@ +# 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. + +spring: + application: + name: dubbo-samples-nativeimage-consumer +dubbo: + application: + name: ${spring.application.name} + logger: slf4j + qos-port: 22223 + registry: + address: zookeeper://127.0.0.1:2181 + +logging: + pattern: + level: '%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]' + +server: + port: 9091 \ No newline at end of file diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/logback-spring.xml b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/resources/logback-spring.xml similarity index 93% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/logback-spring.xml rename to 2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/resources/logback-spring.xml index 8bbedf11d2..44c945aa91 100644 --- a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/logback-spring.xml +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-consumer/src/main/resources/logback-spring.xml @@ -24,10 +24,10 @@ - + - + - + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/.mvn/wrapper/maven-wrapper.properties b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/.mvn/wrapper/maven-wrapper.properties new file mode 100755 index 0000000000..ca5ab4bab1 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# 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 +# +# https://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. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/Dockerfile b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/Dockerfile new file mode 100644 index 0000000000..fdabeeafec --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/Dockerfile @@ -0,0 +1,22 @@ +# Using Oracle GraalVM for JDK 17 Community Edition +FROM container-registry.oracle.com/graalvm/native-image-community:17-ol8 AS builder + +# Set the working directory to /home/app +WORKDIR /build + +# Copy the source code into the image for building +COPY . /build + +ARG APP_FILE + +# Build +RUN ./mvnw clean package --no-transfer-progress native:compile -Pnative -U + +# The deployment Image +FROM container-registry.oracle.com/os/oraclelinux:9-slim + +EXPOSE 50052 + +# Copy the native executable into the containers +COPY --from=builder /build/target/dubbo-samples-native-image-registry-provider app +ENTRYPOINT ["/app"] \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/Dockerfile.jvm b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/Dockerfile.jvm new file mode 100644 index 0000000000..2bf1d7b930 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/Dockerfile.jvm @@ -0,0 +1,19 @@ +# Using Oracle GraalVM for JDK 17 +FROM openjdk:17 + +# Set the working directory to /home/app +WORKDIR /build +COPY . /build + +RUN ./mvnw clean package -U + +# JAR file will be specified by passing in a build time argument to docker build +ARG APP_FILE + +EXPOSE 50052 + +# opy the JAR file into the root and rename +COPY ./target/${APP_FILE} app.jar + +# Run java with the jar file when the container starts up +CMD ["java","-jar","app.jar"] \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/README.md b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/README.md new file mode 100644 index 0000000000..1f8ee605a3 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/README.md @@ -0,0 +1,35 @@ +# Build native image +The following steps work for all platforms - MacOS, Windows, and Linux. + +To do this, we've provided a [multistage Docker build file](./Dockerfile) for building a Docker image containing your native executable inside a Docker container. + +## Build the provider + +1. Containerise the native executable using the following command: + + ```shell + docker build -f ./Dockerfile --build-arg APP_FILE=dubbo-samples-native-image-provider -t provider-native:1.0.0 . + ``` + +2. Run the application: + + ```shell + docker run --rm --name native -p 50052:50052 provider-native:1.0.0 + ``` + +3. Open a new terminal window, call the endpoint using `curl`: + + ```shell + curl \ + --header "Content-Type: application/json" \ + --data '{"name":"Dubbo"}' \ + http://localhost:50052/org.apache.dubbo.nativeimage.DemoService/sayHello/ + ``` + + It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. + +4. To stop the application, first get the container id using `docker ps`, and then run: + + ```shell + docker rm -f + ``` diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/mvnw b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/mvnw new file mode 100755 index 0000000000..b7f064624f --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/mvnw @@ -0,0 +1,287 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.1.1 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + printf '%s' "$(cd "$basedir"; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname $0)") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $wrapperUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + QUIET="--quiet" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + elif command -v curl > /dev/null; then + QUIET="--silent" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=`cygpath --path --windows "$javaSource"` + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/mvnw.cmd b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/mvnw.cmd new file mode 100644 index 0000000000..474c9d6b74 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/mvnw.cmd @@ -0,0 +1,187 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.1.1 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/pom.xml b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/pom.xml new file mode 100644 index 0000000000..f9182ee126 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/pom.xml @@ -0,0 +1,257 @@ + + + + org.apache + apache + 23 + + + + 4.0.0 + org.apache.dubbo + 1.0-SNAPSHOT + dubbo-samples-native-image-registry-provider + + + 17 + 17 + 17 + 5.1.0 + 3.3.0-beta.1 + 3.0.5 + 3.0.5 + 0.9.23 + + + + + + org.apache.dubbo + dubbo-bom + ${dubbo.version} + pom + import + + + + + + + org.apache.dubbo + dubbo-spring-boot-starter + + + + org.springframework + spring-context + + + org.springframework + spring-beans + + + org.springframework + spring-web + + + org.springframework.boot + spring-boot-autoconfigure + + + org.apache.dubbo + dubbo-serialization-hessian2 + + + + + org.apache.dubbo + dubbo-zookeeper-curator5-spring-boot-starter + + + ch.qos.logback + logback-classic + + + ch.qos.logback + logback-core + + + org.slf4j + slf4j-log4j12 + + + org.slf4j + slf4j-api + + + log4j + log4j + + + com.fasterxml.jackson.core + jackson-databind + + + + + + org.apache.dubbo + dubbo-native + + + + org.apache.dubbo + dubbo-config-spring6 + + + + com.google.protobuf + protobuf-java + 3.19.6 + + + com.google.protobuf + protobuf-java-util + 3.19.6 + + + + org.springframework.boot + spring-boot-starter + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-starter-logging + ${spring-boot.version} + + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot.version} + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-maven-plugin.version} + + + + repackage + + + + + + + + + + native + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.10.1 + + 17 + true + true + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-maven-plugin.version} + + + process-aot + + process-aot + + + + + + org.graalvm.buildtools + native-maven-plugin + ${native-maven-plugin.version} + + ${project.build.outputDirectory} + + true + + 22.3 + + + + add-reachability-metadata + + add-reachability-metadata + + + + + + org.apache.dubbo + dubbo-maven-plugin + ${dubbo.version} + + org.apache.dubbo.registry.provider.NativeDemoProviderRegistryApplication + + + + process-sources + + dubbo-process-aot + + + + + + + + + + + + apache.snapshots.https + Apache Development Snapshot Repository + https://repository.apache.org/content/repositories/snapshots + default + + false + + + true + daily + + + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/DemoService.java b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/DemoService.java new file mode 100644 index 0000000000..81b023dbd3 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/DemoService.java @@ -0,0 +1,29 @@ +/* + * 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.registry; + + +import java.util.concurrent.CompletableFuture; + +public interface DemoService { + + HelloResponse sayHello(HelloRequest request); + + default CompletableFuture sayHelloAsync(HelloRequest request) { + return CompletableFuture.completedFuture(sayHello(request)); + } +} diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/HelloRequest.java b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/HelloRequest.java new file mode 100644 index 0000000000..737f900c47 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/HelloRequest.java @@ -0,0 +1,35 @@ +/* + * 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.registry; + +import java.io.Serializable; + +public class HelloRequest implements Serializable { + private String name; + + public HelloRequest(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/HelloResponse.java b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/HelloResponse.java new file mode 100644 index 0000000000..d17d9efa12 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/HelloResponse.java @@ -0,0 +1,36 @@ +/* + * 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.registry; + + +import java.io.Serializable; + +public class HelloResponse implements Serializable { + private String response; + + public HelloResponse(String response) { + this.response = response; + } + + public String getResponse() { + return response; + } + + public void setResponse(String response) { + this.response = response; + } +} diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/provider/DemoServiceImpl.java b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/provider/DemoServiceImpl.java new file mode 100644 index 0000000000..2834b51126 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/provider/DemoServiceImpl.java @@ -0,0 +1,37 @@ +/* + * 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.registry.provider; + + +import org.apache.dubbo.config.annotation.DubboService; +import org.apache.dubbo.registry.DemoService; +import org.apache.dubbo.registry.HelloRequest; +import org.apache.dubbo.registry.HelloResponse; +import org.apache.dubbo.rpc.RpcContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@DubboService +public class DemoServiceImpl implements DemoService { + + private static final Logger logger = LoggerFactory.getLogger(DemoServiceImpl.class); + + public HelloResponse sayHello(HelloRequest request) { + logger.info("Hello " + request.getName() + ", request from consumer: " + RpcContext.getContext().getRemoteAddress()); + return new HelloResponse(request.getName()); + } +} diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/provider/NativeDemoProviderRegistryApplication.java b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/provider/NativeDemoProviderRegistryApplication.java new file mode 100644 index 0000000000..98c9cc7df7 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/java/org/apache/dubbo/registry/provider/NativeDemoProviderRegistryApplication.java @@ -0,0 +1,39 @@ +/* + * 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.registry.provider; + +import org.apache.dubbo.config.spring.context.annotation.EnableDubbo; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import java.lang.management.ManagementFactory; +import java.lang.management.RuntimeMXBean; +import java.util.concurrent.CountDownLatch; + +@SpringBootApplication(scanBasePackages = {"org.apache.dubbo.registry.provider"}) +@EnableDubbo(scanBasePackages = {"org.apache.dubbo.registry.provider"}) +public class NativeDemoProviderRegistryApplication { + + public static void main(String[] args) throws InterruptedException { + SpringApplication.run(NativeDemoProviderRegistryApplication.class, args); + RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); + System.out.println("dubbo provider application started, The time taken to start the application is " + + (System.currentTimeMillis() - runtimeMXBean.getStartTime()) +" ms"); + new CountDownLatch(1).await(); + } +} diff --git a/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/resources/application.yml new file mode 100644 index 0000000000..8bf58eef6f --- /dev/null +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/resources/application.yml @@ -0,0 +1,37 @@ +# 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. +spring: + application: + name: dubbo-samples-nativeimage-provider +dubbo: + application: + name: ${spring.application.name} + logger: slf4j + qos-port: 22222 + protocol: + name: tri + port: 50052 + serialization: fastjson2 + provider: + serialization: fastjson2 + registry: + address: "zookeeper://127.0.0.1:2181" + +logging: + pattern: + level: '%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]' + +server: + port: 9090 \ No newline at end of file diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/logback-spring.xml b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/resources/logback-spring.xml similarity index 93% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/logback-spring.xml rename to 2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/resources/logback-spring.xml index 8bbedf11d2..44c945aa91 100644 --- a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/logback-spring.xml +++ b/2-advanced/dubbo-samples-native-image-registry/dubbo-samples-native-image-registry-provider/src/main/resources/logback-spring.xml @@ -24,10 +24,10 @@ - + - + - + \ No newline at end of file diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-interface/pom.xml b/2-advanced/dubbo-samples-native-image-registry/pom.xml similarity index 69% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-interface/pom.xml rename to 2-advanced/dubbo-samples-native-image-registry/pom.xml index a9918f637c..a7127fcd5c 100644 --- a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-interface/pom.xml +++ b/2-advanced/dubbo-samples-native-image-registry/pom.xml @@ -18,20 +18,15 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - org.apache.dubbo - dubbo-samples-native-image - 1.0-SNAPSHOT - ../pom.xml - - dubbo-samples-native-image-interface - - - 17 - 17 - 17 - + org.apache.dubbo + dubbo-samples-native-image-registry + 1.0-SNAPSHOT + pom + + dubbo-samples-native-image-registry-provider + dubbo-samples-native-image-registry-consumer + diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/.mvn/wrapper/maven-wrapper.properties b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/.mvn/wrapper/maven-wrapper.properties new file mode 100755 index 0000000000..ca5ab4bab1 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# 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 +# +# https://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. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/Dockerfile b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/Dockerfile new file mode 100644 index 0000000000..9a11a6ca24 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/Dockerfile @@ -0,0 +1,22 @@ +# Using Oracle GraalVM for JDK 17 Community Edition +FROM ghcr.io/graalvm/native-image-community:17-muslib AS builder + +# Set the working directory to /home/app +WORKDIR /build + +# Copy the source code into the image for building +COPY . /build + +ARG APP_FILE + +# Build +RUN ./mvnw clean package --no-transfer-progress native:compile -Pnative -U + +# The deployment Image +FROM container-registry.oracle.com/os/oraclelinux:9-slim + +EXPOSE 9091 + +# Copy the native executable into the containers +COPY --from=builder /build/target/${APP_FILE} app +ENTRYPOINT ["/app"] \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/Dockerfile.jvm b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/Dockerfile.jvm new file mode 100644 index 0000000000..bd2097ca13 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/Dockerfile.jvm @@ -0,0 +1,19 @@ +# Using Oracle GraalVM for JDK 17 +FROM openjdk:17 + +# Set the working directory to /home/app +WORKDIR /build +COPY . /build + +RUN ./mvnw clean package -U + +# JAR file will be specified by passing in a build time argument to docker build +ARG APP_FILE + +EXPOSE 9091 + +# opy the JAR file into the root and rename +COPY ./target/${APP_FILE} app.jar + +# Run java with the jar file when the container starts up +CMD ["java","-jar","app.jar"] \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/README.md b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/README.md new file mode 100644 index 0000000000..735dab5bde --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/README.md @@ -0,0 +1,24 @@ +# Build native image +The following steps work for all platforms - MacOS, Windows, and Linux. + +To do this, we've provided a [multistage Docker build file](./Dockerfile) for building a Docker image containing your native executable inside a Docker container. + +## Build the consumer + +1. Containerise the native executable using the following command: + + ```shell + docker build -f ./Dockerfile --build-arg APP_FILE=dubbo-samples-native-image-consumer -t consumer-native:1.0.0 . + ``` + +2. Run the application: + + ```shell + docker run --rm --name native-consumer consumer-native:1.0.0 + ``` + +3. To stop the application, first get the container id using `docker ps`, and then run: + + ```shell + docker rm -f + ``` diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/mvnw b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/mvnw new file mode 100755 index 0000000000..b7f064624f --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/mvnw @@ -0,0 +1,287 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.1.1 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + printf '%s' "$(cd "$basedir"; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname $0)") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $wrapperUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + QUIET="--quiet" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + elif command -v curl > /dev/null; then + QUIET="--silent" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=`cygpath --path --windows "$javaSource"` + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/mvnw.cmd b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/mvnw.cmd new file mode 100644 index 0000000000..474c9d6b74 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/mvnw.cmd @@ -0,0 +1,187 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.1.1 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/pom.xml b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/pom.xml similarity index 92% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/pom.xml rename to 2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/pom.xml index 47925fff84..61516c132d 100644 --- a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/pom.xml +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/pom.xml @@ -17,14 +17,16 @@ - 4.0.0 - org.apache.dubbo - dubbo-samples-native-image - 1.0-SNAPSHOT - ../pom.xml + org.apache + apache + 23 + + 4.0.0 + org.apache.dubbo + 1.0-SNAPSHOT dubbo-samples-native-image-consumer @@ -32,16 +34,14 @@ 17 17 5.1.0 + 3.3.0-beta.1 + 3.0.5 + 3.0.5 + 0.9.23 - - org.apache.dubbo - dubbo-samples-native-image-interface - ${project.parent.version} - - org.apache.dubbo dubbo-remoting-netty4 @@ -71,6 +71,21 @@ dubbo-rpc-dubbo ${dubbo.version} + + org.apache.dubbo + dubbo-rpc-triple + ${dubbo.version} + + + com.google.protobuf + protobuf-java + 3.19.6 + + + com.google.protobuf + protobuf-java-util + 3.19.6 + org.apache.dubbo diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-interface/src/main/java/org/apache/dubbo/nativeimage/DemoService.java b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/DemoService.java similarity index 100% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-interface/src/main/java/org/apache/dubbo/nativeimage/DemoService.java rename to 2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/DemoService.java diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-interface/src/main/java/org/apache/dubbo/nativeimage/HelloRequest.java b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/HelloRequest.java similarity index 100% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-interface/src/main/java/org/apache/dubbo/nativeimage/HelloRequest.java rename to 2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/HelloRequest.java diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-interface/src/main/java/org/apache/dubbo/nativeimage/HelloResponse.java b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/HelloResponse.java similarity index 100% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-interface/src/main/java/org/apache/dubbo/nativeimage/HelloResponse.java rename to 2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/HelloResponse.java diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/consumer/NativeDemoConsumerApplication.java b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/consumer/NativeDemoConsumerApplication.java similarity index 98% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/consumer/NativeDemoConsumerApplication.java rename to 2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/consumer/NativeDemoConsumerApplication.java index dac1526b3c..f6777ffcb0 100644 --- a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/consumer/NativeDemoConsumerApplication.java +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/java/org/apache/dubbo/nativeimage/consumer/NativeDemoConsumerApplication.java @@ -31,7 +31,7 @@ @EnableDubbo(scanBasePackages = {"org.apache.dubbo.nativeimage.consumer"}) public class NativeDemoConsumerApplication { - @DubboReference + @DubboReference(url = "tri://127.0.0.1:50052") private DemoService demoService; public static void main(String[] args) throws InterruptedException { diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/application.yml b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/application.yml similarity index 81% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/application.yml rename to 2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/application.yml index f2aeb6e124..d13a7739e1 100644 --- a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/application.yml +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/application.yml @@ -21,17 +21,6 @@ dubbo: name: ${spring.application.name} logger: slf4j qos-port: 22223 - protocol: - name: dubbo - port: -1 - serialization: fastjson2 - registry: - id: zk-registry - address: zookeeper://127.0.0.1:2181 - config-center: - address: zookeeper://127.0.0.1:2181 - metadata-report: - address: zookeeper://127.0.0.1:2181 provider: serialization: fastjson2 consumer: diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/logback-spring.xml b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/logback-spring.xml new file mode 100644 index 0000000000..44c945aa91 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-consumer/src/main/resources/logback-spring.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/.mvn/wrapper/maven-wrapper.properties b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/.mvn/wrapper/maven-wrapper.properties new file mode 100755 index 0000000000..ca5ab4bab1 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# 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 +# +# https://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. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/Dockerfile b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/Dockerfile new file mode 100644 index 0000000000..8fa6cb1551 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/Dockerfile @@ -0,0 +1,22 @@ +# Using Oracle GraalVM for JDK 17 Community Edition +FROM container-registry.oracle.com/graalvm/native-image-community:17-ol8 AS builder + +# Set the working directory to /home/app +WORKDIR /build + +# Copy the source code into the image for building +COPY . /build + +# Build +RUN ./mvnw clean package --no-transfer-progress native:compile -Pnative -U + +ARG APP_FILE + +# The deployment Image +FROM container-registry.oracle.com/os/oraclelinux:9-slim + +EXPOSE 50052 + +# Copy the native executable into the containers +COPY --from=builder /build/target/${APP_FILE} app +ENTRYPOINT ["/app"] \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/Dockerfile.jvm b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/Dockerfile.jvm new file mode 100644 index 0000000000..2bf1d7b930 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/Dockerfile.jvm @@ -0,0 +1,19 @@ +# Using Oracle GraalVM for JDK 17 +FROM openjdk:17 + +# Set the working directory to /home/app +WORKDIR /build +COPY . /build + +RUN ./mvnw clean package -U + +# JAR file will be specified by passing in a build time argument to docker build +ARG APP_FILE + +EXPOSE 50052 + +# opy the JAR file into the root and rename +COPY ./target/${APP_FILE} app.jar + +# Run java with the jar file when the container starts up +CMD ["java","-jar","app.jar"] \ No newline at end of file diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/README.md b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/README.md new file mode 100644 index 0000000000..1f8ee605a3 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/README.md @@ -0,0 +1,35 @@ +# Build native image +The following steps work for all platforms - MacOS, Windows, and Linux. + +To do this, we've provided a [multistage Docker build file](./Dockerfile) for building a Docker image containing your native executable inside a Docker container. + +## Build the provider + +1. Containerise the native executable using the following command: + + ```shell + docker build -f ./Dockerfile --build-arg APP_FILE=dubbo-samples-native-image-provider -t provider-native:1.0.0 . + ``` + +2. Run the application: + + ```shell + docker run --rm --name native -p 50052:50052 provider-native:1.0.0 + ``` + +3. Open a new terminal window, call the endpoint using `curl`: + + ```shell + curl \ + --header "Content-Type: application/json" \ + --data '{"name":"Dubbo"}' \ + http://localhost:50052/org.apache.dubbo.nativeimage.DemoService/sayHello/ + ``` + + It should generate a random nonsense verse in the style of the poem Jabberwocky by Lewis Carrol. + +4. To stop the application, first get the container id using `docker ps`, and then run: + + ```shell + docker rm -f + ``` diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/mvnw b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/mvnw new file mode 100755 index 0000000000..b7f064624f --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/mvnw @@ -0,0 +1,287 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# 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. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.1.1 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + printf '%s' "$(cd "$basedir"; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname $0)") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $wrapperUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + QUIET="--quiet" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + elif command -v curl > /dev/null; then + QUIET="--silent" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=`cygpath --path --windows "$javaSource"` + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/mvnw.cmd b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/mvnw.cmd new file mode 100644 index 0000000000..474c9d6b74 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/mvnw.cmd @@ -0,0 +1,187 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.1.1 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/pom.xml b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/pom.xml similarity index 92% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/pom.xml rename to 2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/pom.xml index 4a1f6d3005..397a72ff2a 100644 --- a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/pom.xml +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/pom.xml @@ -17,14 +17,16 @@ - 4.0.0 - org.apache.dubbo - dubbo-samples-native-image - 1.0-SNAPSHOT - ../pom.xml + org.apache + apache + 23 + + 4.0.0 + org.apache.dubbo + 1.0-SNAPSHOT dubbo-samples-native-image-provider @@ -32,16 +34,13 @@ 17 17 5.1.0 + 3.3.0-beta.1 + 3.0.5 + 3.0.5 + 0.9.23 - - - org.apache.dubbo - dubbo-samples-native-image-interface - ${project.parent.version} - - org.apache.dubbo dubbo-remoting-netty4 @@ -65,6 +64,22 @@ dubbo-rpc-dubbo ${dubbo.version} + + org.apache.dubbo + dubbo-rpc-triple + ${dubbo.version} + + + com.google.protobuf + protobuf-java + 3.19.6 + + + com.google.protobuf + protobuf-java-util + 3.19.6 + + org.apache.dubbo diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/DemoService.java b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/DemoService.java new file mode 100644 index 0000000000..8e615efe86 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/DemoService.java @@ -0,0 +1,29 @@ +/* + * 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.nativeimage; + + +import java.util.concurrent.CompletableFuture; + +public interface DemoService { + + HelloResponse sayHello(HelloRequest request); + + default CompletableFuture sayHelloAsync(HelloRequest request) { + return CompletableFuture.completedFuture(sayHello(request)); + } +} diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/HelloRequest.java b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/HelloRequest.java new file mode 100644 index 0000000000..ada62c98cd --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/HelloRequest.java @@ -0,0 +1,35 @@ +/* + * 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.nativeimage; + +import java.io.Serializable; + +public class HelloRequest implements Serializable { + private String name; + + public HelloRequest(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/HelloResponse.java b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/HelloResponse.java new file mode 100644 index 0000000000..c2133cbde3 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/HelloResponse.java @@ -0,0 +1,36 @@ +/* + * 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.nativeimage; + + +import java.io.Serializable; + +public class HelloResponse implements Serializable { + private String response; + + public HelloResponse(String response) { + this.response = response; + } + + public String getResponse() { + return response; + } + + public void setResponse(String response) { + this.response = response; + } +} diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/provider/DemoServiceImpl.java b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/provider/DemoServiceImpl.java similarity index 100% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/provider/DemoServiceImpl.java rename to 2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/provider/DemoServiceImpl.java diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/provider/NativeDemoProviderApplication.java b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/provider/NativeDemoProviderApplication.java similarity index 100% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/provider/NativeDemoProviderApplication.java rename to 2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/java/org/apache/dubbo/nativeimage/provider/NativeDemoProviderApplication.java diff --git a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/application.yml b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/application.yml similarity index 84% rename from 1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/application.yml rename to 2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/application.yml index 2b18539fe5..51e725a9c6 100644 --- a/1-basic/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/application.yml +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/application.yml @@ -20,16 +20,9 @@ dubbo: name: ${spring.application.name} logger: slf4j protocol: - name: dubbo - port: -1 + name: tri + port: 50052 serialization: fastjson2 - registry: - id: zk-registry - address: zookeeper://127.0.0.1:2181 - config-center: - address: zookeeper://127.0.0.1:2181 - metadata-report: - address: zookeeper://127.0.0.1:2181 provider: serialization: fastjson2 consumer: diff --git a/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/logback-spring.xml b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/logback-spring.xml new file mode 100644 index 0000000000..44c945aa91 --- /dev/null +++ b/2-advanced/dubbo-samples-native-image/dubbo-samples-native-image-provider/src/main/resources/logback-spring.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/1-basic/dubbo-samples-native-image/pom.xml b/2-advanced/dubbo-samples-native-image/pom.xml similarity index 66% rename from 1-basic/dubbo-samples-native-image/pom.xml rename to 2-advanced/dubbo-samples-native-image/pom.xml index d0df60685b..3ce62d4427 100644 --- a/1-basic/dubbo-samples-native-image/pom.xml +++ b/2-advanced/dubbo-samples-native-image/pom.xml @@ -18,12 +18,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - org.apache - apache - 23 - - org.apache.dubbo dubbo-samples-native-image @@ -32,18 +26,7 @@ dubbo-samples-native-image-provider - dubbo-samples-native-image-interface dubbo-samples-native-image-consumer - - 17 - 3.3.0-beta.1-SNAPSHOT - 3.0.5 - 3.0.5 - 0.9.23 - 1.8 - 1.8 - - diff --git a/1-basic/dubbo-samples-spring-xml/case-configuration.yml b/2-advanced/dubbo-samples-spring-xml/case-configuration.yml similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/case-configuration.yml rename to 2-advanced/dubbo-samples-spring-xml/case-configuration.yml diff --git a/1-basic/dubbo-samples-spring-xml/case-versions.conf b/2-advanced/dubbo-samples-spring-xml/case-versions.conf similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/case-versions.conf rename to 2-advanced/dubbo-samples-spring-xml/case-versions.conf diff --git a/1-basic/dubbo-samples-spring-xml/pom.xml b/2-advanced/dubbo-samples-spring-xml/pom.xml similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/pom.xml rename to 2-advanced/dubbo-samples-spring-xml/pom.xml diff --git a/1-basic/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java b/2-advanced/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java rename to 2-advanced/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/api/GreetingsService.java diff --git a/1-basic/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/client/AlwaysApplication.java b/2-advanced/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/client/AlwaysApplication.java similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/client/AlwaysApplication.java rename to 2-advanced/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/client/AlwaysApplication.java diff --git a/1-basic/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/client/Application.java b/2-advanced/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/client/Application.java similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/client/Application.java rename to 2-advanced/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/client/Application.java diff --git a/1-basic/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/provider/Application.java b/2-advanced/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/provider/Application.java similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/provider/Application.java rename to 2-advanced/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/provider/Application.java diff --git a/1-basic/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java b/2-advanced/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java rename to 2-advanced/dubbo-samples-spring-xml/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java diff --git a/1-basic/dubbo-samples-spring-xml/src/main/resources/log4j.properties b/2-advanced/dubbo-samples-spring-xml/src/main/resources/log4j.properties similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/src/main/resources/log4j.properties rename to 2-advanced/dubbo-samples-spring-xml/src/main/resources/log4j.properties diff --git a/1-basic/dubbo-samples-spring-xml/src/main/resources/spring/dubbo-demo-consumer.xml b/2-advanced/dubbo-samples-spring-xml/src/main/resources/spring/dubbo-demo-consumer.xml similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/src/main/resources/spring/dubbo-demo-consumer.xml rename to 2-advanced/dubbo-samples-spring-xml/src/main/resources/spring/dubbo-demo-consumer.xml diff --git a/1-basic/dubbo-samples-spring-xml/src/main/resources/spring/dubbo-demo-provider.xml b/2-advanced/dubbo-samples-spring-xml/src/main/resources/spring/dubbo-demo-provider.xml similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/src/main/resources/spring/dubbo-demo-provider.xml rename to 2-advanced/dubbo-samples-spring-xml/src/main/resources/spring/dubbo-demo-provider.xml diff --git a/1-basic/dubbo-samples-spring-xml/src/test/java/org/apache/dubbo/samples/test/GreetingsServiceIT.java b/2-advanced/dubbo-samples-spring-xml/src/test/java/org/apache/dubbo/samples/test/GreetingsServiceIT.java similarity index 100% rename from 1-basic/dubbo-samples-spring-xml/src/test/java/org/apache/dubbo/samples/test/GreetingsServiceIT.java rename to 2-advanced/dubbo-samples-spring-xml/src/test/java/org/apache/dubbo/samples/test/GreetingsServiceIT.java diff --git a/2-advanced/dubbo-samples-springcloud/dubbo-call-sc/pom.xml b/2-advanced/dubbo-samples-springcloud/dubbo-call-sc/pom.xml index 53b44fad36..98b4a4da26 100644 --- a/2-advanced/dubbo-samples-springcloud/dubbo-call-sc/pom.xml +++ b/2-advanced/dubbo-samples-springcloud/dubbo-call-sc/pom.xml @@ -38,7 +38,7 @@ 1.8 1.8 3.7.0 - 3.3.0-beta.1-SNAPSHOT + 3.3.0-beta.1 4.13.1 2.7.8 2021.0.5 diff --git a/2-advanced/dubbo-samples-springcloud/sc-call-dubbo/pom.xml b/2-advanced/dubbo-samples-springcloud/sc-call-dubbo/pom.xml index 1681f0f6cb..1f336ff16a 100644 --- a/2-advanced/dubbo-samples-springcloud/sc-call-dubbo/pom.xml +++ b/2-advanced/dubbo-samples-springcloud/sc-call-dubbo/pom.xml @@ -40,7 +40,7 @@ 1.8 3.7.0 4.13.1 - 3.3.0-beta.1-SNAPSHOT + 3.3.0-beta.1 2.7.8 2021.0.5 2021.0.5.0 diff --git a/2-advanced/dubbo-samples-triple-grpc/pom.xml b/2-advanced/dubbo-samples-triple-grpc/pom.xml index 5481d28958..394f832061 100644 --- a/2-advanced/dubbo-samples-triple-grpc/pom.xml +++ b/2-advanced/dubbo-samples-triple-grpc/pom.xml @@ -29,7 +29,7 @@ dubbo-samples-triple-grpc - 3.2.6 + 3.3.0-beta.1 1.8 1.8 1.54.1 diff --git a/2-advanced/dubbo-samples-triple-no-idl/README.md b/2-advanced/dubbo-samples-triple-no-idl/README.md index a782f49ba4..fba87491ed 100644 --- a/2-advanced/dubbo-samples-triple-no-idl/README.md +++ b/2-advanced/dubbo-samples-triple-no-idl/README.md @@ -5,7 +5,7 @@ As described in [the Triple protocol documentation](https://dubbo.apache.org/zh- The Java implementation gives you the option of using Triple and HTTP/2 RPC without the need of caring about Protocol Buffers, no IDL, just standard java interface and pojos. ## Run The Demo -Detailed explanation of this demo can be found [here](https://dubbo.apache.org/zh-cn/overview/quickstart/rpc/java/). +Detailed explanation of this demo can be found [here](https://dubbo.apache.org/zh-cn/overview/mannual/java-sdk/quick-start). Make sure you are in `dubbo-samples-triple-no-idl` before running the following commands diff --git a/2-advanced/dubbo-samples-triple-no-idl/pom.xml b/2-advanced/dubbo-samples-triple-no-idl/pom.xml index f231ce00bc..02bbc70ad7 100644 --- a/2-advanced/dubbo-samples-triple-no-idl/pom.xml +++ b/2-advanced/dubbo-samples-triple-no-idl/pom.xml @@ -29,7 +29,7 @@ dubbo-samples-triple-no-idl - 3.2.6 + 3.3.0-beta.1 1.8 1.8 3.7.0 @@ -48,6 +48,11 @@ ${dubbo.version} pom + + com.google.protobuf + protobuf-java + 3.19.6 + diff --git a/2-advanced/dubbo-samples-triple-streaming/README.md b/2-advanced/dubbo-samples-triple-streaming/README.md index 1577ffd22a..0184bfc87f 100644 --- a/2-advanced/dubbo-samples-triple-streaming/README.md +++ b/2-advanced/dubbo-samples-triple-streaming/README.md @@ -3,7 +3,7 @@ This example shows how you can use streaming RPC with Dubbo Triple protocol. As described in [the Triple protocol documentation](https://dubbo.apache.org/zh-cn/overview/reference/protocols/triple/), Dubbo triple protocol is fully compatible with gRPC, so it supports client streaming, server streaming and bi-streaming. ## Run The Demo -Detailed explanation of this demo can be found [here](https://dubbo.apache.org/zh-cn/overview/quickstart/rpc/java/). +Detailed explanation of this demo can be found [here](https://dubbo.apache.org/zh-cn/overview/mannual/java-sdk/quick-start). ```shell mvn clean compile #Compile and generate code diff --git a/2-advanced/dubbo-samples-triple-streaming/pom.xml b/2-advanced/dubbo-samples-triple-streaming/pom.xml index e5030140a1..d0bb5ddfa9 100644 --- a/2-advanced/dubbo-samples-triple-streaming/pom.xml +++ b/2-advanced/dubbo-samples-triple-streaming/pom.xml @@ -29,7 +29,7 @@ dubbo-samples-triple-streaming - 3.2.6 + 3.3.0-beta.1 1.8 1.8 3.7.0 diff --git a/2-advanced/pom.xml b/2-advanced/pom.xml index 49473389b1..11a1e1836d 100644 --- a/2-advanced/pom.xml +++ b/2-advanced/pom.xml @@ -60,5 +60,10 @@ dubbo-samples-service-discovery dubbo-samples-triple-grpc dubbo-samples-triple-no-idl + dubbo-samples-native-image + dubbo-samples-native-image-registry + dubbo-samples-annotation + dubbo-samples-spring-xml + dubbo-samples-api-with-registry \ No newline at end of file diff --git a/99-integration/dubbo-samples-test-register-3-3/pom.xml b/99-integration/dubbo-samples-test-register-3-3/pom.xml index d36679f306..eb62c77db7 100644 --- a/99-integration/dubbo-samples-test-register-3-3/pom.xml +++ b/99-integration/dubbo-samples-test-register-3-3/pom.xml @@ -36,7 +36,7 @@ Dubbo Samples Test For Register on Dubbo 3.3 - 3.3.0-beta.1-SNAPSHOT + 3.3.0-beta.1 5.9.2 1.8 1.8