You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by il...@apache.org on 2019/04/30 02:09:26 UTC
[incubator-dubbo-samples] branch master updated: update zookeeper
example
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 b895325 update zookeeper example
new 1193220 Merge branch 'master' of https://github.com/apache/incubator-dubbo-samples
b895325 is described below
commit b895325c3bfc5239b29edd26156d56ad6f3fe70b
Author: Ian Luo <ia...@gmail.com>
AuthorDate: Tue Apr 30 10:08:42 2019 +0800
update zookeeper example
---
dubbo-samples-consul/pom.xml | 15 ++
dubbo-samples-zookeeper/README.md | 30 +++
dubbo-samples-zookeeper/pom.xml | 248 +--------------------
.../apache/dubbo/samples/ConsumerBootstrap.java | 8 +-
.../apache/dubbo/samples/ProviderBootstrap.java | 3 +-
.../samples/action/GreetingServiceConsumer.java | 3 +-
.../samples/impl/AnnotatedGreetingService.java | 2 +-
.../src/main/resources/docker/docker-compose.yml | 7 +
.../resources/spring/dubbo-consumer.properties | 12 +-
.../resources/spring/dubbo-provider.properties | 13 +-
10 files changed, 77 insertions(+), 264 deletions(-)
diff --git a/dubbo-samples-consul/pom.xml b/dubbo-samples-consul/pom.xml
new file mode 100644
index 0000000..88af11c
--- /dev/null
+++ b/dubbo-samples-consul/pom.xml
@@ -0,0 +1,15 @@
+<?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-consul</artifactId>
+
+
+</project>
diff --git a/dubbo-samples-zookeeper/README.md b/dubbo-samples-zookeeper/README.md
new file mode 100644
index 0000000..b1088d4
--- /dev/null
+++ b/dubbo-samples-zookeeper/README.md
@@ -0,0 +1,30 @@
+# Dubbo Zookeeper Example
+
+This example shows how a global transaction manager works in Dubbo framework. Here we use [seata](https://github.com/seata/seata) as an example, but other transaction managers are possible to work with Dubbo too if they provide the corresponding Dubbo filter implementation.
+
+## How To Run
+
+#### Step 1. Start Zookeeper as Registry Center
+
+In this example, a docker compose file is provided to start the required zookeeper easily. But at the same time, it requires you to prepare docker environment as a prerequisite. You can refer to [docker quick start](https://www.docker.com/get-started) to install.
+
+```bash
+cd src/main/resources/docker
+docker-compose up
+```
+
+#### Step 2. Build Examples
+
+Execute the following maven command under *dubbo-samples-zookeeper* directory, or simply import the whole sample project into IDE.
+
+```bash
+mvn clean package
+```
+
+#### Step 3. Run Examples
+
+0. Run *ProviderBootstrap* to start service provider
+0. Run *ConsumerBootstrap* to start service consumer, you should see the following result in the console:
+```bash
+result: hello, zookeeper
+```
diff --git a/dubbo-samples-zookeeper/pom.xml b/dubbo-samples-zookeeper/pom.xml
index 051dc76..4410480 100644
--- a/dubbo-samples-zookeeper/pom.xml
+++ b/dubbo-samples-zookeeper/pom.xml
@@ -28,178 +28,36 @@
<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>
+ <artifactId>dubbo-dependencies-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>
+ <version>${dubbo.version}</version>
</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>
+ <artifactId>dubbo-dependencies-zookeeper</artifactId>
+ <version>${dubbo.version}</version>
+ <type>pom</type>
</dependency>
</dependencies>
-
-
<build>
<pluginManagement>
<plugins>
@@ -220,98 +78,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>
</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-zookeeper/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java b/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java
index fc0368f..57ee9fb 100644
--- a/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java
+++ b/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/ConsumerBootstrap.java
@@ -19,24 +19,22 @@
package org.apache.dubbo.samples;
-import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
+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;
-import java.io.IOException;
-
public class ConsumerBootstrap {
- public static void main(String[] args) throws IOException {
+ public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);
context.start();
GreetingServiceConsumer greetingServiceConsumer = context.getBean(GreetingServiceConsumer.class);
String hello = greetingServiceConsumer.doSayHello("zookeeper");
System.out.println("result: " + hello);
- System.in.read();
}
@Configuration
diff --git a/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java b/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
index 4d104ba..a51928b 100644
--- a/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
+++ b/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/ProviderBootstrap.java
@@ -19,7 +19,8 @@
package org.apache.dubbo.samples;
-import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
+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;
diff --git a/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java b/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
index 86e9d61..93ab690 100644
--- a/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
+++ b/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/action/GreetingServiceConsumer.java
@@ -19,8 +19,9 @@
package org.apache.dubbo.samples.action;
-import com.alibaba.dubbo.config.annotation.Reference;
+import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.samples.api.GreetingService;
+
import org.springframework.stereotype.Component;
@Component("annotatedConsumer")
diff --git a/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java b/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java
index 76df11a..5e7ba3d 100644
--- a/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java
+++ b/dubbo-samples-zookeeper/src/main/java/org/apache/dubbo/samples/impl/AnnotatedGreetingService.java
@@ -19,7 +19,7 @@
package org.apache.dubbo.samples.impl;
-import com.alibaba.dubbo.config.annotation.Service;
+import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.samples.api.GreetingService;
@Service
diff --git a/dubbo-samples-zookeeper/src/main/resources/docker/docker-compose.yml b/dubbo-samples-zookeeper/src/main/resources/docker/docker-compose.yml
new file mode 100644
index 0000000..6d3fe10
--- /dev/null
+++ b/dubbo-samples-zookeeper/src/main/resources/docker/docker-compose.yml
@@ -0,0 +1,7 @@
+version: '3.3'
+services:
+ zookeeper:
+ image: "zookeeper:latest"
+ ports:
+ - "2181:2181"
+
diff --git a/dubbo-samples-zookeeper/src/main/resources/spring/dubbo-consumer.properties b/dubbo-samples-zookeeper/src/main/resources/spring/dubbo-consumer.properties
index be31a3c..2acf426 100644
--- a/dubbo-samples-zookeeper/src/main/resources/spring/dubbo-consumer.properties
+++ b/dubbo-samples-zookeeper/src/main/resources/spring/dubbo-consumer.properties
@@ -6,19 +6,17 @@
# 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
-# find out environment variable $DOCKER_HOST is and use its IP for zookeeper address if you are
-# running zookeeper in docker.
-dubbo.registry.address=zookeeper://$DOCKER_HOST:2181
-dubbo.consumer.timeout=3000
\ No newline at end of file
+dubbo.registry.address=zookeeper://localhost:2181
+dubbo.consumer.timeout=3000
diff --git a/dubbo-samples-zookeeper/src/main/resources/spring/dubbo-provider.properties b/dubbo-samples-zookeeper/src/main/resources/spring/dubbo-provider.properties
index 8a9cdfe..46eea3b 100644
--- a/dubbo-samples-zookeeper/src/main/resources/spring/dubbo-provider.properties
+++ b/dubbo-samples-zookeeper/src/main/resources/spring/dubbo-provider.properties
@@ -6,20 +6,17 @@
# 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
-# find out environment variable $DOCKER_HOST is and use its IP for zookeeper address if you are
-# running zookeeper in docker.
-dubbo.registry.address=zookeeper://$DOCKER_HOST:2181
+dubbo.registry.address=zookeeper://localhost:2181
dubbo.protocol.name=dubbo
-dubbo.protocol.port=20880
\ No newline at end of file
+dubbo.protocol.port=20880
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org