Skip to content

Commit b800097

Browse files
committed
feat: add dubbo-nacos-sample
1 parent d0475e7 commit b800097

File tree

13 files changed

+414
-0
lines changed

13 files changed

+414
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*/target/
2+
.idea
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Dubbo使用Nacos作为注册中心
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.boot.dubbo</groupId>
7+
<artifactId>dubbo-spring-boot-registry-nacos</artifactId>
8+
<version>${revision}</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>dubbo-spring-boot-registry-nacos-consumer-sample</artifactId>
14+
<name>Apache Dubbo Spring Boot :: Samples : Registry Nacos :: Consumer Sample</name>
15+
16+
<properties>
17+
<nacos.version>1.1.1</nacos.version>
18+
</properties>
19+
20+
<dependencies>
21+
<!-- Spring Boot dependencies -->
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter</artifactId>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.apache.dubbo</groupId>
29+
<artifactId>dubbo-spring-boot-starter</artifactId>
30+
<version>${revision}</version>
31+
</dependency>
32+
33+
<!-- Dubbo Registry Nacos -->
34+
<dependency>
35+
<groupId>org.apache.dubbo</groupId>
36+
<artifactId>dubbo-registry-nacos</artifactId>
37+
<version>${revision}</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>com.alibaba.nacos</groupId>
42+
<artifactId>nacos-client</artifactId>
43+
<version>${nacos.version}</version>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.boot.dubbo</groupId>
48+
<artifactId>dubbo-spring-boot-sample-api</artifactId>
49+
<version>${revision}</version>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-starter-web</artifactId>
55+
<version>${spring-boot.version}</version>
56+
</dependency>
57+
</dependencies>
58+
59+
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>org.springframework.boot</groupId>
63+
<artifactId>spring-boot-maven-plugin</artifactId>
64+
<version>${spring-boot.version}</version>
65+
<executions>
66+
<execution>
67+
<goals>
68+
<goal>repackage</goal>
69+
</goals>
70+
</execution>
71+
</executions>
72+
<configuration>
73+
<executable>false</executable>
74+
<finalName>${project.artifactId}-${spring-boot.version}</finalName>
75+
<outputDirectory>${user.dir}/target</outputDirectory>
76+
</configuration>
77+
</plugin>
78+
</plugins>
79+
</build>
80+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.boot.dubbo.nacos.demo.consumer.bootstrap;
18+
19+
import org.springframework.boot.autoconfigure.SpringBootApplication;
20+
import org.springframework.boot.builder.SpringApplicationBuilder;
21+
22+
/**
23+
* Dubbo Registry Nacos Consumer Bootstrap
24+
*
25+
* @author luoliang
26+
*/
27+
@SpringBootApplication
28+
public class DubboRegistryNacosConsumerBootstrap {
29+
30+
public static void main(String[] args) {
31+
new SpringApplicationBuilder(DubboRegistryNacosConsumerBootstrap.class)
32+
.run(args);
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.boot.dubbo.nacos.demo.consumer.bootstrap.web;
2+
3+
import org.apache.dubbo.config.annotation.Reference;
4+
import org.boot.dubbo.nacos.demo.consumer.DemoService;
5+
import org.springframework.web.bind.annotation.GetMapping;
6+
import org.springframework.web.bind.annotation.PathVariable;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RestController;
9+
10+
/**
11+
* @author luoliang
12+
* @date 2019/11/13
13+
*/
14+
@RestController
15+
@RequestMapping("/demo")
16+
public class DemoController {
17+
18+
@Reference(version = "${demo.service.version}")
19+
private DemoService demoService;
20+
21+
@GetMapping("/{name}")
22+
public String sayHello(@PathVariable("name") String name) {
23+
return demoService.sayHello(name);
24+
}
25+
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
spring:
2+
application:
3+
name: dubbo-registry-nacos-consumer-sample
4+
5+
demo:
6+
service:
7+
version: 1.0.0
8+
9+
nacos:
10+
host: localhost
11+
port: 8848
12+
13+
dubbo:
14+
registry:
15+
address: nacos://${nacos.host}:${nacos.port}
16+
17+
server:
18+
port: 8081

boot-dubbo-registry-nacos/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>2.1.9.RELEASE</version>
9+
<relativePath/> <!-- lookup parent from repository -->
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
14+
<artifactId>dubbo-spring-boot-registry-nacos</artifactId>
15+
<groupId>org.boot.dubbo</groupId>
16+
<name>Apache Dubbo Spring Boot :: Samples : Registry Nacos</name>
17+
<description>Apache Dubbo Spring Boot Registry Nacos Samples</description>
18+
<version>${revision}</version>
19+
<packaging>pom</packaging>
20+
21+
<modules>
22+
<module>provider-sample</module>
23+
<module>consumer-sample</module>
24+
<module>sample-api</module>
25+
</modules>
26+
27+
<properties>
28+
<java.version>1.8</java.version>
29+
<revision>2.7.3</revision>
30+
<spring-boot.version>2.1.9.RELEASE</spring-boot.version>
31+
</properties>
32+
</project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<groupId>org.boot.dubbo</groupId>
7+
<artifactId>dubbo-spring-boot-registry-nacos</artifactId>
8+
<version>${revision}</version>
9+
<relativePath>../pom.xml</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
12+
13+
<artifactId>dubbo-spring-boot-registry-nacos-provider-sample</artifactId>
14+
<name>Apache Dubbo Spring Boot :: Samples : Registry Nacos :: Provider Sample</name>
15+
16+
<properties>
17+
<nacos.version>1.1.1</nacos.version>
18+
</properties>
19+
20+
<dependencies>
21+
<!-- Spring Boot dependencies -->
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter</artifactId>
25+
</dependency>
26+
27+
<dependency>
28+
<groupId>org.apache.dubbo</groupId>
29+
<artifactId>dubbo-spring-boot-starter</artifactId>
30+
<version>${revision}</version>
31+
</dependency>
32+
33+
<!-- Dubbo Registry Nacos -->
34+
<dependency>
35+
<groupId>org.apache.dubbo</groupId>
36+
<artifactId>dubbo-registry-nacos</artifactId>
37+
<version>${revision}</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>com.alibaba.nacos</groupId>
42+
<artifactId>nacos-client</artifactId>
43+
<version>${nacos.version}</version>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.boot.dubbo</groupId>
48+
<artifactId>dubbo-spring-boot-sample-api</artifactId>
49+
<version>${revision}</version>
50+
</dependency>
51+
</dependencies>
52+
53+
<build>
54+
<plugins>
55+
<plugin>
56+
<groupId>org.springframework.boot</groupId>
57+
<artifactId>spring-boot-maven-plugin</artifactId>
58+
<version>${spring-boot.version}</version>
59+
<executions>
60+
<execution>
61+
<goals>
62+
<goal>repackage</goal>
63+
</goals>
64+
</execution>
65+
</executions>
66+
<configuration>
67+
<executable>false</executable>
68+
<finalName>${project.artifactId}-${spring-boot.version}</finalName>
69+
<outputDirectory>${user.dir}/target</outputDirectory>
70+
</configuration>
71+
</plugin>
72+
</plugins>
73+
</build>
74+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.boot.dubbo.nacos.demo.provider.bootstrap;
18+
19+
import org.boot.dubbo.nacos.demo.provider.service.DefaultDemoService;
20+
21+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
22+
import org.springframework.boot.builder.SpringApplicationBuilder;
23+
24+
/**
25+
* Dubbo Registry Nacos Provider Bootstrap
26+
*
27+
* @author luoliang
28+
* @see DefaultDemoService
29+
* @since 2.7.0
30+
*/
31+
@EnableAutoConfiguration
32+
public class DubboRegistryNacosProviderBootstrap {
33+
34+
public static void main(String[] args) {
35+
new SpringApplicationBuilder(DubboRegistryNacosProviderBootstrap.class)
36+
.run(args);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.boot.dubbo.nacos.demo.provider.service;
18+
19+
import org.apache.dubbo.config.annotation.Service;
20+
import org.boot.dubbo.nacos.demo.consumer.DemoService;
21+
import org.springframework.beans.factory.annotation.Value;
22+
23+
24+
/**
25+
* Default {@link DemoService}
26+
*
27+
* @see DemoService
28+
* @since 2.7.0
29+
*/
30+
@Service(version = "${demo.service.version}")
31+
public class DefaultDemoService implements DemoService {
32+
/**
33+
* The default value of ${dubbo.application.name} is ${spring.application.name}
34+
*/
35+
@Value("${dubbo.application.name}")
36+
private String serviceName;
37+
38+
@Override
39+
public String sayHello(String name) {
40+
return String.format("[%s] : Hello, %s", serviceName, name);
41+
}
42+
43+
}

0 commit comments

Comments
 (0)