Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
175 changed files
with
14,550 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -28,3 +28,6 @@ target/ | ||
# system ignore | ||
.DS_Store | ||
Thumbs.db | ||
|
||
# generated code | ||
*/build/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -23,4 +23,6 @@ public interface DemoService { | ||
|
||
String sayHello(String name); | ||
|
||
void testVoid(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Dubbo Demo | ||
|
||
This directory contains basic usages of Dubbo to help Dubbo developers for debugging and smoke test purpose. If you are looking for Dubbo samples for study purpose, you should look into [here](https://github.com/apache/dubbo-samples) where you will find comprehensive usages for how to use Dubbo in different scenarios with the different features. | ||
|
||
## How To Build | ||
|
||
To build all demo applications from the source code, simply step into '*dubbo-demo*' directory and use maven to build: | ||
|
||
```bash | ||
mvn clean package | ||
``` | ||
|
||
After build completes, a couple of fat jars are generated under '*target*' directory under each module directories, for example: '*dubbo-demo-api-provider-${project.version}.jar*' can be found under the directory '*dubbo-demo/dubbo-demo-api/dubbo-demo-api-provider/target*'. | ||
|
||
## How To Run | ||
|
||
Since the generated artifacts are fat jars backed by spring boot maven plugin, they can be executed directly with '*java -jar*', and since multicast is used for service registration, a necessary system property '**-Djava.net.preferIPv4Stack=true**' is required in order to registry and discover the demo service properly. | ||
|
||
Use '*dubbo-demo/dubbo-demo-api*' as an example, to start the provider '*dubbo-demo-api-provider*', execute the following command: | ||
|
||
```bash | ||
java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-api-provider-${project.version}.jar | ||
``` | ||
|
||
To run the consumer '*dubbo-demo-api-consumer*', execute the following command: | ||
|
||
```bash | ||
java -Djava.net.preferIPv4Stack=true -jar dubbo-demo-api-consumer-${project.version}.jar | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Dubbo自动发现并消费原生Spring Cloud服务,以Consul为注册中心。 | ||
|
||
* Spring MVC方式开发服务端 | ||
* 以标准Dubbo方式开发客户端 | ||
* 首先,定义标准JAX-RS注解的接口(与Provider端相对应) | ||
* Registry指定 | ||
* 同时消费,要使用Multiple Registry策略 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<!-- | ||
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. | ||
--> | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-call-sc</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>dubbo-sc-consumer</artifactId> | ||
<packaging>jar</packaging> | ||
<name>${project.artifactId}</name> | ||
<description>The demo consumer module of dubbo project</description> | ||
<properties> | ||
<skip_maven_deploy>true</skip_maven_deploy> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-demo-interface</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-registry-multicast</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-registry-nacos</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba.nacos</groupId> | ||
<artifactId>nacos-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-registry-zookeeper</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-configcenter-zookeeper</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-configcenter-nacos</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-metadata-report-nacos</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-config-spring</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-rpc-dubbo</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-rpc-rest</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-remoting-netty4</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-serialization-hessian2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-registry-consul</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
*/ | ||
package org.apache.dubbo.demo.consumer; | ||
|
||
import org.apache.dubbo.samples.microservices.sc.rest.User; | ||
import org.apache.dubbo.samples.microservices.sc.rest.UserService; | ||
|
||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
|
||
public class Application { | ||
public static void main(String[] args) { | ||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("spring/dubbo-consumer.xml"); | ||
context.start(); | ||
UserService userService = context.getBean("userService", UserService.class); | ||
User user = userService.getUser(1L); | ||
System.out.println("result: " + user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* | ||
* 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.microservices.sc.rest; | ||
|
||
|
||
import javax.validation.constraints.Min; | ||
import javax.validation.constraints.NotNull; | ||
import javax.validation.constraints.Size; | ||
import javax.xml.bind.annotation.XmlAccessType; | ||
import javax.xml.bind.annotation.XmlAccessorType; | ||
import javax.xml.bind.annotation.XmlRootElement; | ||
import java.io.Serializable; | ||
|
||
@XmlRootElement | ||
@XmlAccessorType(XmlAccessType.FIELD) | ||
public class User implements Serializable { | ||
|
||
@NotNull | ||
@Min(1L) | ||
private Long id; | ||
|
||
@NotNull | ||
@Size(min = 6, max = 50) | ||
private String name; | ||
|
||
public User() { | ||
} | ||
|
||
public User(Long id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "User (" + | ||
"id=" + id + | ||
", name='" + name + '\'' + | ||