Skip to content

Commit

Permalink
add dubbo_v3.x demo #48
Browse files Browse the repository at this point in the history
  • Loading branch information
heqingpan committed Aug 5, 2024
1 parent 1fe8534 commit 94e8e62
Show file tree
Hide file tree
Showing 17 changed files with 449 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sdk-examples/java/dubbo_v3.x/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tmp/

23 changes: 23 additions & 0 deletions sdk-examples/java/dubbo_v3.x/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

# r-nacos dubbo_v3.x 说明

本样例基于dubbo v3.2.14版本,需要jdk 17以上版本。



## 使用方式

1. 启动r-nacos
2. 切换到dubbo_v3.x样例目录
3. 本地打包 `mvn package` (如果有问题可以用 `mvn install` )
4. 运行service: `java -jar dubbo-demo-service/target/dubbo-demo-service-1.0-SNAPSHOT.jar`
5. 运行api: `java -jar dubbo-demo-api/target/dubbo-demo-api-1.0-SNAPSHOT.jar`
6. 访问api: `curl "http://127.0.0.1:20785/hi?name=r-nacos"`

```sh
curl "http://127.0.0.1:20785/hi?name=r-nacos"
[dubbo-demo-service] : Hello, r-nacos
```



2 changes: 2 additions & 0 deletions sdk-examples/java/dubbo_v3.x/dubbo-demo-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/

68 changes: 68 additions & 0 deletions sdk-examples/java/dubbo_v3.x/dubbo-demo-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.rnacos.demo</groupId>
<artifactId>dubbo-demo-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>dubbo-demo-api</artifactId>
<name>dubbo-demo-api</name>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.rnacos.demo</groupId>
<artifactId>dubbo-demo-common</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
<!--
-->

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-nacos-spring-boot-starter</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>


Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.rnacos.demo;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


/**
*
*/
@SpringBootApplication
@EnableDubbo
public class App
{
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.rnacos.demo.foo.api;

import com.rnacos.demo.foo.DemoService;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Component
@RestController
public class FooController {

@DubboReference
private DemoService demoService;

@GetMapping("/hi")
public String hello(@RequestParam("name")String name){
if(name==null){
name = "default";
}
return demoService.sayHello(name);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
server:
port: 20785
spring:
application:
name: dubbo-demo-api

dubbo:
application:
logger: slf4j
name: ${spring.application.name}
qos-enable: false
check-serializable: false
registry:
address: nacos://${nacos.address:127.0.0.1}:8848?username=nacos&password=nacos
protocol:
port: 20885
name: dubbo

2 changes: 2 additions & 0 deletions sdk-examples/java/dubbo_v3.x/dubbo-demo-common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/

28 changes: 28 additions & 0 deletions sdk-examples/java/dubbo_v3.x/dubbo-demo-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.rnacos.demo</groupId>
<artifactId>dubbo-demo-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>dubbo-demo-common</artifactId>
<name>dubbo-demo-common</name>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.rnacos.demo;

/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.rnacos.demo.foo;

public interface DemoService {
String sayHello(String name);
}
2 changes: 2 additions & 0 deletions sdk-examples/java/dubbo_v3.x/dubbo-demo-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target/

67 changes: 67 additions & 0 deletions sdk-examples/java/dubbo_v3.x/dubbo-demo-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>com.rnacos.demo</groupId>
<artifactId>dubbo-demo-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>dubbo-demo-service</artifactId>
<name>dubbo-demo-service</name>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.rnacos.demo</groupId>
<artifactId>dubbo-demo-common</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</dependency>
<!--
-->

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-nacos-spring-boot-starter</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.rnacos.demo;

import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


/**
*
*/
@SpringBootApplication
@EnableDubbo
public class App
{
public static void main(String[] args) {
SpringApplication.run(App.class,args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.rnacos.demo.foo.service.impl;

import com.rnacos.demo.foo.DemoService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Value;


@DubboService
public class DemoServiceImpl implements DemoService {
@Value("${spring.application.name}")
private String serviceName;

public String sayHello(String name) {
//return String.format("Hello, %s",name);
return String.format("[%s] : Hello, %s",serviceName,name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
server:
port: 20784
spring:
application:
name: dubbo-demo-service

dubbo:
application:
logger: slf4j
name: ${spring.application.name}
qos-enable: false
check-serializable: false
registry:
address: nacos://${nacos.address:127.0.0.1}:8848?username=nacos&password=nacos
protocol:
port: 20884
name: dubbo
Loading

0 comments on commit 94e8e62

Please sign in to comment.