dubbo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i...@apache.org
Subject [incubator-dubbo-samples] branch master updated: correct basic examples
Date Tue, 30 Apr 2019 07:34:32 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new dd06c90  correct basic examples
dd06c90 is described below

commit dd06c907e62f40a631d983c9f711edf051ce3807
Author: Ian Luo <ian.luo@gmail.com>
AuthorDate: Tue Apr 30 15:34:01 2019 +0800

    correct basic examples
---
 dubbo-samples-api/README.md                        |   6 +-
 dubbo-samples-api/pom.xml                          | 295 +--------------------
 .../apache/dubbo/samples/client/Application.java   |  19 +-
 .../samples/{server => provider}/Application.java  |   3 +-
 .../{server => provider}/GreetingsServiceImpl.java |   2 +-
 .../dubbo/samples/provider/DemoServiceImpl.java    |  14 +-
 .../samples/provider}/GreetingsServiceImpl.java    |   2 +-
 .../samples/provider/MultipleServiceProvider.java  |  79 ++++++
 .../apache/dubbo/samples/provider/Provider.java    |  63 +++++
 9 files changed, 165 insertions(+), 318 deletions(-)

diff --git a/dubbo-samples-api/README.md b/dubbo-samples-api/README.md
index 8057ecc..965d6ea 100644
--- a/dubbo-samples-api/README.md
+++ b/dubbo-samples-api/README.md
@@ -6,11 +6,11 @@ This sample code demonstrates building up dubbo service provider and service
con
 
 ```bash
 mvn clean package
-mvn -Djava.net.preferIPv4Stack=true -Dexec.mainClass=Application exec:java
+mvn -Djava.net.preferIPv4Stack=true -Dexec.mainClass=org.apache.dubbo.samples.provider.Application
exec:java
 ```
 
 ## Invoke the service consumer
 
 ```bash
-mvn -Djava.net.preferIPv4Stack=true -Dexec.mainClass=Application exec:java
-```
\ No newline at end of file
+mvn -Djava.net.preferIPv4Stack=true -Dexec.mainClass=org.apache.dubbo.samples.client.Application
exec:java
+```
diff --git a/dubbo-samples-api/pom.xml b/dubbo-samples-api/pom.xml
index 16da187..f155c86 100644
--- a/dubbo-samples-api/pom.xml
+++ b/dubbo-samples-api/pom.xml
@@ -29,188 +29,18 @@
     <properties>
         <source.level>1.8</source.level>
         <target.level>1.8</target.level>
-        <spring.version>4.3.16.RELEASE</spring.version>
-        <dubbo.version>2.7.0</dubbo.version>
-        <dubbo.rpc.version>2.7.0</dubbo.rpc.version>
-        <zookeeper.version>3.4.13</zookeeper.version>
-        <curator.version>4.0.1</curator.version>
-        <validation-api.version>1.1.0.Final</validation-api.version>
-        <hibernate-validator.version>4.2.0.Final</hibernate-validator.version>
-        <resteasy.version>3.0.19.Final</resteasy.version>
-        <curator-client.version>4.0.1</curator-client.version>
-        <swagger.version>1.5.19</swagger.version>
-        <tomcat.version>7.0.88</tomcat.version>
-        <servlet.version>3.0.1</servlet.version>
-        <maven_checkstyle_version>3.0.0</maven_checkstyle_version>
-        <apache-rat-plugin.version>0.12</apache-rat-plugin.version>
-        <spring-boot.version>1.5.13.RELEASE</spring-boot.version>
+        <dubbo.version>2.7.1</dubbo.version>
     </properties>
 
-    <dependencyManagement>
-        <dependencies>
-            <dependency>
-                <groupId>org.springframework</groupId>
-                <artifactId>spring-framework-bom</artifactId>
-                <version>${spring.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-            <dependency>
-                <!-- Import dependency management from Spring Boot -->
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-dependencies</artifactId>
-                <version>${spring-boot.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-            <dependency>
-                <groupId>io.netty</groupId>
-                <artifactId>netty-all</artifactId>
-                <version>4.1.16.Final</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.dubbo</groupId>
-                <artifactId>dubbo-bom</artifactId>
-                <version>${dubbo.version}</version>
-                <type>pom</type>
-                <scope>import</scope>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.dubbo</groupId>
-                <artifactId>dubbo</artifactId>
-                <version>${dubbo.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>org.apache.thrift</groupId>
-                        <artifactId>libthrift</artifactId>
-                    </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.dubbo</groupId>
-                <artifactId>dubbo-rpc-rest</artifactId>
-                <version>${dubbo.rpc.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.zookeeper</groupId>
-                <artifactId>zookeeper</artifactId>
-                <version>${zookeeper.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.curator</groupId>
-                <artifactId>curator-framework</artifactId>
-                <version>${curator.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>org.apache.zookeeper</groupId>
-                        <artifactId>zookeeper</artifactId>
-                    </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
-                <groupId>javax.validation</groupId>
-                <artifactId>validation-api</artifactId>
-                <version>${validation-api.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.hibernate</groupId>
-                <artifactId>hibernate-validator</artifactId>
-                <version>${hibernate-validator.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.jboss.resteasy</groupId>
-                <artifactId>resteasy-jackson-provider</artifactId>
-                <version>${resteasy.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.curator</groupId>
-                <artifactId>curator-client</artifactId>
-                <version>${curator-client.version}</version>
-                <exclusions>
-                    <exclusion>
-                        <groupId>org.apache.zookeeper</groupId>
-                        <artifactId>zookeeper</artifactId>
-                    </exclusion>
-                </exclusions>
-            </dependency>
-            <dependency>
-                <groupId>javax.servlet</groupId>
-                <artifactId>javax.servlet-api</artifactId>
-                <version>${servlet.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.tomcat.embed</groupId>
-                <artifactId>tomcat-embed-core</artifactId>
-                <version>${tomcat.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>org.apache.tomcat.embed</groupId>
-                <artifactId>tomcat-embed-logging-juli</artifactId>
-                <version>${tomcat.version}</version>
-            </dependency>
-            <!-- swagger -->
-            <dependency>
-                <groupId>io.swagger</groupId>
-                <artifactId>swagger-annotations</artifactId>
-                <version>${swagger.version}</version>
-            </dependency>
-            <dependency>
-                <groupId>io.swagger</groupId>
-                <artifactId>swagger-jaxrs</artifactId>
-                <version>${swagger.version}</version>
-            </dependency>
-        </dependencies>
-    </dependencyManagement>
-
     <dependencies>
         <dependency>
-            <groupId>org.apache.curator</groupId>
-            <artifactId>curator-framework</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>io.netty</groupId>
-                    <artifactId>netty</artifactId>
-                </exclusion>
-                <exclusion>
-                    <groupId>org.apache.zookeeper</groupId>
-                    <artifactId>zookeeper</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.zookeeper</groupId>
-            <artifactId>zookeeper</artifactId>
-        </dependency>
-        <dependency>
             <groupId>org.apache.dubbo</groupId>
             <artifactId>dubbo</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.dubbo</groupId>
-            <artifactId>dubbo-configcenter-zookeeper</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>io.netty</groupId>
-            <artifactId>netty-all</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.slf4j</groupId>
-            <artifactId>slf4j-simple</artifactId>
+            <version>${dubbo.version}</version>
         </dependency>
     </dependencies>
 
-
-
     <build>
-        <pluginManagement>
-            <plugins>
-                <plugin>
-                    <groupId>org.springframework.boot</groupId>
-                    <artifactId>spring-boot-maven-plugin</artifactId>
-                    <version>${spring-boot.version}</version>
-                </plugin>
-            </plugins>
-        </pluginManagement>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
@@ -221,127 +51,6 @@
                     <target>${target.level}</target>
                 </configuration>
             </plugin>
-            <plugin>
-                <groupId>org.apache.rat</groupId>
-                <artifactId>apache-rat-plugin</artifactId>
-                <version>${apache-rat-plugin.version}</version>
-                <executions>
-                    <execution>
-                        <id>verify.rat</id>
-                        <phase>verify</phase>
-                        <goals>
-                            <goal>check</goal>
-                        </goals>
-                        <configuration>
-                            <excludes>
-                                <exclude>**/*.versionsBackup</exclude>
-                                <exclude>**/.idea/</exclude>
-                                <exclude>**/*.iml</exclude>
-                                <exclude>**/*.txt</exclude>
-                                <exclude>**/*.load</exclude>
-                                <exclude>**/*.flex</exclude>
-                                <exclude>**/*.fc</exclude>
-                                <exclude>**/*.javascript</exclude>
-                                <exclude>**/*.properties</exclude>
-                                <exclude>**/*.thrift</exclude>
-                                <exclude>**/*.sh</exclude>
-                                <exclude>**/*.bat</exclude>
-                                <exclude>**/*.md</exclude>
-                                <exclude>.git/</exclude>
-                                <exclude>.gitignore</exclude>
-                                <!-- ASF jenkins box puts the Maven repo in our root directory.
-->
-                                <exclude>.repository/</exclude>
-                                <exclude>**/.settings/*</exclude>
-                                <exclude>**/.classpath</exclude>
-                                <exclude>**/.project</exclude>
-                                <exclude>**/target/**</exclude>
-                                <exclude>**/*.log</exclude>
-                                <exclude>CODE_OF_CONDUCT.md</exclude>
-                                <exclude>.codecov.yml</exclude>
-                                <exclude>.travis.yml</exclude>
-                                <exclude>PULL_REQUEST_TEMPLATE.md</exclude>
-                                <exclude>CONTRIBUTING.md</exclude>
-                                <exclude>README.md</exclude>
-                                <exclude>**/codestyle/*</exclude>
-                                <exclude>**/resources/META-INF/**</exclude>
-                                <exclude>**/webapp/swagger/**</exclude>
-                                <exclude>**/org/apache/dubbo/samples/rpc/nativethrift/api/DemoService.java</exclude>
-                            </excludes>
-                        </configuration>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.codehaus.mojo</groupId>
-                <artifactId>exec-maven-plugin</artifactId>
-                <version>1.6.0</version>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>java</goal>
-                        </goals>
-                    </execution>
-                </executions>
-            </plugin>
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-compiler-plugin</artifactId>
-                <version>3.7.0</version>
-                <configuration>
-                    <source>1.8</source>
-                    <target>1.8</target>
-                    <!-- should be obsoleted -->
-                    <!--<annotationProcessorPaths>-->
-                    <!--<path>-->
-                    <!--<groupId>com.alibaba</groupId>-->
-                    <!--<artifactId>dubbo-async-processer</artifactId>-->
-                    <!--<version>1.0.0-SNAPSHOT</version>-->
-                    <!--</path>-->
-                    <!--</annotationProcessorPaths>-->
-                </configuration>
-            </plugin>
         </plugins>
     </build>
-
-    <profiles>
-        <profile>
-            <id>checkstyle</id>
-            <activation>
-                <jdk>[1.8,)</jdk>
-            </activation>
-            <build>
-                <plugins>
-                    <plugin>
-                        <groupId>org.apache.maven.plugins</groupId>
-                        <artifactId>maven-checkstyle-plugin</artifactId>
-                        <version>${maven_checkstyle_version}</version>
-                        <dependencies>
-                            <dependency>
-                                <groupId>com.puppycrawl.tools</groupId>
-                                <artifactId>checkstyle</artifactId>
-                                <version>8.9</version>
-                            </dependency>
-                        </dependencies>
-                        <executions>
-                            <execution>
-                                <id>checkstyle-validation</id>
-                                <phase>validate</phase>
-                                <configuration>
-                                    <configLocation>../codestyle/checkstyle.xml</configLocation>
-                                    <suppressionsLocation>../codestyle/checkstyle-suppressions.xml</suppressionsLocation>
-                                    <encoding>UTF-8</encoding>
-                                    <consoleOutput>true</consoleOutput>
-                                    <failOnViolation>true</failOnViolation>
-                                </configuration>
-                                <goals>
-                                    <goal>check</goal>
-                                </goals>
-                            </execution>
-                        </executions>
-                    </plugin>
-                </plugins>
-            </build>
-        </profile>
-    </profiles>
-
 </project>
diff --git a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/Application.java
b/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/Application.java
index a64542d..e80f82e 100644
--- a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/Application.java
+++ b/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/client/Application.java
@@ -21,21 +21,16 @@ package org.apache.dubbo.samples.client;
 import org.apache.dubbo.config.ApplicationConfig;
 import org.apache.dubbo.config.ReferenceConfig;
 import org.apache.dubbo.config.RegistryConfig;
-import org.apache.dubbo.rpc.service.GenericService;
+import org.apache.dubbo.samples.api.GreetingsService;
 
 public class Application {
     public static void main(String[] args) {
-        System.setProperty("java.net.preferIPv4Stack", "true");
-        ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
-        reference.setApplication(new ApplicationConfig("first-dubbo-client"));
-        reference.setRegistry(new RegistryConfig("zookeeper://127.0.0.1:2181"));
-//        reference.setInterface(GreetingsService.class);
-        reference.setGeneric(true);
-        reference.setInterface("org.apache.dubbo.samples.api.GreetingsService");
-        GenericService genericService = reference.get();
-
-
-        Object message = genericService.$invoke("sayHi", new String[]{"java.lang.String"},
new Object[]{"aaa"});
+        ReferenceConfig<GreetingsService> reference = new ReferenceConfig<>();
+        reference.setApplication(new ApplicationConfig("first-dubbo-consumer"));
+        reference.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234"));
+        reference.setInterface(GreetingsService.class);
+        GreetingsService service = reference.get();
+        String message = service.sayHi("dubbo");
         System.out.println(message);
     }
 }
diff --git a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/Application.java
b/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/Application.java
similarity index 93%
rename from dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/Application.java
rename to dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/Application.java
index b795069..88d5f58 100644
--- a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/Application.java
+++ b/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/Application.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.dubbo.samples.server;
+package org.apache.dubbo.samples.provider;
 
 
 import org.apache.dubbo.config.ApplicationConfig;
@@ -27,7 +27,6 @@ import java.io.IOException;
 
 public class Application {
     public static void main(String[] args) throws IOException {
-        System.setProperty("java.net.preferIPv4Stack", "true");
         ServiceConfig<GreetingsService> service = new ServiceConfig<>();
         service.setApplication(new ApplicationConfig("first-dubbo-provider"));
         service.setRegistry(new RegistryConfig("multicast://224.5.6.7:1234"));
diff --git a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/GreetingsServiceImpl.java
b/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
similarity index 95%
copy from dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/GreetingsServiceImpl.java
copy to dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
index 78735bf..d0d4448 100644
--- a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/GreetingsServiceImpl.java
+++ b/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.dubbo.samples.server;
+package org.apache.dubbo.samples.provider;
 
 import org.apache.dubbo.samples.api.GreetingsService;
 
diff --git a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/GreetingsServiceImpl.java
b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/DemoServiceImpl.java
similarity index 78%
copy from dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/GreetingsServiceImpl.java
copy to dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/DemoServiceImpl.java
index 78735bf..2902273 100644
--- a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/GreetingsServiceImpl.java
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/DemoServiceImpl.java
@@ -14,14 +14,16 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+package org.apache.dubbo.samples.provider;
 
-package org.apache.dubbo.samples.server;
+import org.apache.dubbo.samples.api.DemoService;
 
-import org.apache.dubbo.samples.api.GreetingsService;
-
-public class GreetingsServiceImpl implements GreetingsService {
+/**
+ *
+ */
+public class DemoServiceImpl implements DemoService {
     @Override
-    public String sayHi(String name) {
-        return "hi, " + name;
+    public String sayHello() {
+        return "Hello, you!";
     }
 }
diff --git a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/GreetingsServiceImpl.java
b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
similarity index 95%
rename from dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/GreetingsServiceImpl.java
rename to dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
index 78735bf..d0d4448 100644
--- a/dubbo-samples-api/src/main/java/org/apache/dubbo/samples/server/GreetingsServiceImpl.java
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/GreetingsServiceImpl.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.dubbo.samples.server;
+package org.apache.dubbo.samples.provider;
 
 import org.apache.dubbo.samples.api.GreetingsService;
 
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/MultipleServiceProvider.java
b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/MultipleServiceProvider.java
new file mode 100644
index 0000000..8490d91
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/MultipleServiceProvider.java
@@ -0,0 +1,79 @@
+/*
+ * 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.provider;
+
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ConfigCenterConfig;
+import org.apache.dubbo.config.RegistryConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.samples.api.DemoService;
+import org.apache.dubbo.samples.api.GreetingsService;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+public class MultipleServiceProvider {
+    private static ConfigCenterConfig configCenter = new ConfigCenterConfig();
+    private static ApplicationConfig application = new ApplicationConfig("api-dubbo-provider");
+    private static RegistryConfig registry1 = new RegistryConfig();
+    private static RegistryConfig registry2 = new RegistryConfig();
+
+    static {
+        configCenter.setExternalConfig(getExternalConfiguration());
+        registry1.setAddress("zookeeper://127.0.0.1:2181");
+        registry2.setAddress("zookeeper://127.0.0.1:2181");
+    }
+
+    public static void main(String[] args) throws Exception {
+        ServiceConfig<GreetingsService> greetingsService = new ServiceConfig<>();
+        greetingsService.setApplication(application);
+        greetingsService.setConfigCenter(configCenter);
+        greetingsService.setRegistries(Arrays.asList(registry1, registry2));
+        greetingsService.setInterface(GreetingsService.class);
+        greetingsService.setRef(new GreetingsServiceImpl());
+        greetingsService.export();
+
+        ServiceConfig<DemoService> demoService = new ServiceConfig<>();
+        demoService.setApplication(application);
+        demoService.setConfigCenter(configCenter);
+        demoService.setInterface(DemoService.class);
+        demoService.setRegistries(Arrays.asList(registry1, registry2));
+        demoService.setRef(new DemoServiceImpl());
+        demoService.export();
+
+        System.out.println("Dubbo provider started successfully!");
+        System.in.read();
+    }
+
+    /**
+     * If you don't want to use ConfigCenter provided by dubbo, you can set external configuration
to Dubbo directly.
+     * In this sample, we created a Map instance manually and put a value into it, but in
reality,
+     * the external configurations will most likely being generated from other plugins in
your system.
+     */
+    public static Map<String, String> getExternalConfiguration() {
+        Map<String, String> dubboConfigurations = new HashMap<>();
+        dubboConfigurations.put("dubbo.registry.address", "zookeeper://127.0.0.1:2181");
+        // you will need to add the configcenter address if you want to use the service governance
features in 2.7, e.g., overrides and routers.
+        // but notice it will not be used for gathering startup configurations.
+        dubboConfigurations.put("dubbo.configcenter.address", "zookeeper://127.0.0.1:2181");
+
+        return dubboConfigurations;
+    }
+}
diff --git a/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/Provider.java
b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/Provider.java
new file mode 100644
index 0000000..6ca14bd
--- /dev/null
+++ b/dubbo-samples-configcenter/dubbo-samples-configcenter-api/src/main/java/org/apache/dubbo/samples/provider/Provider.java
@@ -0,0 +1,63 @@
+/*
+ * 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.provider;
+
+
+import org.apache.dubbo.config.ApplicationConfig;
+import org.apache.dubbo.config.ConfigCenterConfig;
+import org.apache.dubbo.config.ServiceConfig;
+import org.apache.dubbo.samples.api.GreetingsService;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Provider {
+
+    private static ConfigCenterConfig configCenter = new ConfigCenterConfig();
+    private static ApplicationConfig applicationConfig = new ApplicationConfig("api-dubbo-provider");
+
+    static {
+        configCenter.setExternalConfig(getExternalConfiguration());
+    }
+
+    public static void main(String[] args) throws Exception {
+        ServiceConfig<GreetingsService> service = new ServiceConfig<>();
+        service.setApplication(applicationConfig);
+        service.setConfigCenter(configCenter);
+        service.setInterface(GreetingsService.class);
+        service.setRef(new GreetingsServiceImpl());
+        service.export();
+        System.out.println("Dubbo provider started successfully!");
+        System.in.read();
+    }
+
+    /**
+     * If you don't want to use ConfigCenter provided by dubbo, you can set external configuration
to Dubbo directly.
+     * In this sample, we created a Map instance manually and put a value into it, but in
reality,
+     * the external configurations will most likely being generated from other plugins in
your system.
+     */
+    public static Map<String, String> getExternalConfiguration() {
+        Map<String, String> dubboConfigurations = new HashMap<>();
+        dubboConfigurations.put("dubbo.registry.address", "zookeeper://127.0.0.1:2181");
+        // you will need to add the configcenter address if you want to use the service governance
features in 2.7, e.g., overrides and routers.
+        // but notice it will not be used for gathering startup configurations.
+        dubboConfigurations.put("dubbo.configcenter.address", "zookeeper://127.0.0.1:2181");
+
+        return dubboConfigurations;
+    }
+}


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


Mime
View raw message