You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by hu...@apache.org on 2019/07/03 02:07:56 UTC

[dubbo-samples] branch master updated: Add nacos samples

This is an automated email from the ASF dual-hosted git repository.

huxing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ecfa68  Add nacos samples
9ecfa68 is described below

commit 9ecfa684ccad7a3a421f5e51d238e2b27d680b0a
Author: Huxing Zhang <hu...@gmail.com>
AuthorDate: Wed Jul 3 10:07:20 2019 +0800

    Add nacos samples
---
 dubbo-samples-nacos/pom.xml                        | 60 ++++++++++++++++++++++
 .../apache/dubbo/samples/ConsumerBootstrap.java    | 46 +++++++++++++++++
 .../apache/dubbo/samples/ProviderBootstrap.java    | 40 +++++++++++++++
 .../samples/action/GreetingServiceConsumer.java    | 36 +++++++++++++
 .../apache/dubbo/samples/api/GreetingService.java  | 26 ++++++++++
 .../samples/impl/AnnotatedGreetingService.java     | 33 ++++++++++++
 .../src/main/resources/log4j.properties            | 24 +++++++++
 .../resources/spring/dubbo-consumer.properties     | 22 ++++++++
 .../resources/spring/dubbo-provider.properties     | 22 ++++++++
 pom.xml                                            |  1 +
 10 files changed, 310 insertions(+)

diff --git a/dubbo-samples-nacos/pom.xml b/dubbo-samples-nacos/pom.xml
new file mode 100644
index 0000000..5c26848
--- /dev/null
+++ b/dubbo-samples-nacos/pom.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         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">
+    <parent>
+        <artifactId>dubbo-samples-all</artifactId>
+        <groupId>org.apache.dubbo</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>dubbo-samples-nacos</artifactId>
+
+    <properties>
+        <source.level>1.8</source.level>
+        <target.level>1.8</target.level>
+        <dubbo.version>2.7.2</dubbo.version>
+    </properties>
+
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.apache.dubbo</groupId>
+                <artifactId>dubbo-dependencies-bom</artifactId>
+                <version>${dubbo.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.dubbo</groupId>
+            <artifactId>dubbo</artifactId>
+            <version>${dubbo.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba.nacos</groupId>
+            <artifactId>nacos-client</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.7.0</version>
+                <configuration>
+                    <source>${source.level}</source>
+                    <target>${target.level}</target>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+
+</project>
\ No newline at end of file
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java b/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java
new file mode 100644
index 0000000..1c52fd5
--- /dev/null
+++ b/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java
@@ -0,0 +1,46 @@
+/*
+ *
+ *   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;
+
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
+import org.apache.dubbo.samples.action.GreetingServiceConsumer;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+
+public class ConsumerBootstrap {
+
+    public static void main(String[] args) {
+        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
+        context.start();
+        GreetingServiceConsumer greetingServiceConsumer = context.getBean(GreetingServiceConsumer.class);
+        String hello = greetingServiceConsumer.doSayHello("nacos");
+        System.out.println("result: " + hello);
+    }
+
+    @Configuration
+    @EnableDubbo(scanBasePackages = "org.apache.dubbo.samples.action")
+    @PropertySource("classpath:/spring/dubbo-consumer.properties")
+    @ComponentScan(value = {"org.apache.dubbo.samples.action"})
+    static class ConsumerConfiguration {
+
+    }
+}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java b/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
new file mode 100644
index 0000000..3c640b6
--- /dev/null
+++ b/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.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;
+
+import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+
+public class ProviderBootstrap {
+
+    public static void main(String[] args) throws Exception {
+        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ProviderConfiguration.class);
+        context.start();
+        System.in.read();
+    }
+
+    @Configuration
+    @EnableDubbo(scanBasePackages = "org.apache.dubbo.samples.impl")
+    @PropertySource("classpath:/spring/dubbo-provider.properties")
+    static class ProviderConfiguration {
+    }
+}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java b/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
new file mode 100644
index 0000000..98266bf
--- /dev/null
+++ b/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.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.samples.action;
+
+import org.apache.dubbo.config.annotation.Reference;
+import org.apache.dubbo.samples.api.GreetingService;
+import org.springframework.stereotype.Component;
+
+@Component("annotatedConsumer")
+public class GreetingServiceConsumer {
+
+    @Reference
+    private GreetingService greetingService;
+
+    public String doSayHello(String name) {
+        return greetingService.sayHello(name);
+    }
+
+}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java b/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
new file mode 100644
index 0000000..997ece7
--- /dev/null
+++ b/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/api/GreetingService.java
@@ -0,0 +1,26 @@
+/*
+ *
+ *   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;
+
+public interface GreetingService {
+
+    String sayHello(String name);
+
+}
diff --git a/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java b/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java
new file mode 100644
index 0000000..5e7ba3d
--- /dev/null
+++ b/dubbo-samples-nacos/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java
@@ -0,0 +1,33 @@
+/*
+ *
+ *   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.impl;
+
+import org.apache.dubbo.config.annotation.Service;
+import org.apache.dubbo.samples.api.GreetingService;
+
+@Service
+public class AnnotatedGreetingService implements GreetingService {
+
+    public String sayHello(String name) {
+        System.out.println("greeting service received: " + name);
+        return "hello, " + name;
+    }
+
+}
diff --git a/dubbo-samples-nacos/src/main/resources/log4j.properties b/dubbo-samples-nacos/src/main/resources/log4j.properties
new file mode 100644
index 0000000..dcb78e2
--- /dev/null
+++ b/dubbo-samples-nacos/src/main/resources/log4j.properties
@@ -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.
+#  
+#
+
+log4j.rootLogger=info, stdout
+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/dubbo-samples-nacos/src/main/resources/spring/dubbo-consumer.properties b/dubbo-samples-nacos/src/main/resources/spring/dubbo-consumer.properties
new file mode 100644
index 0000000..5cc28f7
--- /dev/null
+++ b/dubbo-samples-nacos/src/main/resources/spring/dubbo-consumer.properties
@@ -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.
+#
+#
+
+dubbo.application.name=demo-consumer
+dubbo.registry.address=nacos://localhost:8848
+dubbo.consumer.timeout=3000
diff --git a/dubbo-samples-nacos/src/main/resources/spring/dubbo-provider.properties b/dubbo-samples-nacos/src/main/resources/spring/dubbo-provider.properties
new file mode 100644
index 0000000..5d65dce
--- /dev/null
+++ b/dubbo-samples-nacos/src/main/resources/spring/dubbo-provider.properties
@@ -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.
+#
+#
+dubbo.application.name=demo-provider
+dubbo.registry.address=nacos://localhost:8848
+dubbo.protocol.name=dubbo
+dubbo.protocol.port=20880
diff --git a/pom.xml b/pom.xml
index fb81076..98ba925 100644
--- a/pom.xml
+++ b/pom.xml
@@ -70,6 +70,7 @@
         <module>dubbo-samples-transaction</module>
         <module>dubbo-samples-consul</module>
         <module>dubbo-samples-edas</module>
+        <module>dubbo-samples-nacos</module>
     </modules>
     <properties>
         <!-- Test libs -->


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org