Skip to content

Commit

Permalink
spring boot + dubbo + nacos
Browse files Browse the repository at this point in the history
  • Loading branch information
eacdy committed May 17, 2019
1 parent c1fafd3 commit c922a97
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 0 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
<module>spring-boot-logging-change-logging-level</module>
<module>spring-boot-mybatis-optional</module>
<module>spring-boot-actuator-prometheus-grafana</module>
<module>spring-boot-dubbo-nacos</module>
</modules>
</project>
61 changes: 61 additions & 0 deletions spring-boot-dubbo-nacos/consumer-sample/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xmlns="http:https://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 http:https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.itmuch.dubbo</groupId>
<artifactId>spring-boot-dubbo-nacos</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>consumer-sample</artifactId>

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

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

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</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>com.itmuch.dubbo</groupId>
<artifactId>sample-api</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.itmuch.dubbo;

import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;

@EnableAutoConfiguration
public class ConsumerApplication {
private final Logger logger = LoggerFactory.getLogger(getClass());

@Reference(version = "${demo.service.version}")
private DemoService demoService;

public static void main(String[] args) {
SpringApplication.run(ConsumerApplication.class).close();
}

@Bean
public ApplicationRunner runner() {
return args -> logger.info(demoService.sayHello("test"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
spring:
application:
name: consumer-sample
dubbo:
registry:
address: nacos:https://${nacos.host}:${nacos.port}
nacos:
host: 127.0.0.1
port: 8848
demo:
service:
version: 1.0.0
90 changes: 90 additions & 0 deletions spring-boot-dubbo-nacos/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xmlns="http:https://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 http:https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.itmuch.dubbo</groupId>
<artifactId>spring-boot-dubbo-nacos</artifactId>
<version>0.0.1-SNAPSHOT</version>

<packaging>pom</packaging>

<properties>
<java.version>1.8</java.version>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<spring-boot.version>2.1.1.RELEASE</spring-boot.version>
<dubbo.version>2.7.1</dubbo.version>
<nacos.version>1.0.0</nacos.version>
</properties>

<modules>
<module>sample-api</module>
<module>provider-sample</module>
<module>consumer-sample</module>
</modules>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.itmuch.dubbo</groupId>
<artifactId>sample-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-bom</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.version}</version>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-registry-nacos</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>${nacos.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
61 changes: 61 additions & 0 deletions spring-boot-dubbo-nacos/provider-sample/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xmlns="http:https://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 http:https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.itmuch.dubbo</groupId>
<artifactId>spring-boot-dubbo-nacos</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>provider-sample</artifactId>

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

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

<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</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>com.itmuch.dubbo</groupId>
<artifactId>sample-api</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.itmuch.dubbo;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;

@EnableAutoConfiguration
public class ProviderApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(ProviderApplication.class)
.run(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.itmuch.dubbo.service;

import com.itmuch.dubbo.DemoService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Value;

@Service(version = "${demo.service.version}")
public class DemoServiceImpl implements DemoService {

@Value("${dubbo.application.name}")
private String serviceName;

@Override
public String sayHello(String name) {
return String.format("[%s] : Hello, %s", serviceName, name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spring:
application:
name: provider-sample
dubbo:
scan:
base-packages: com.itmuch.dubbo.service
protocol:
name: dubbo
port: -1
registry:
address: nacos:https://${nacos.host}:${nacos.port}
demo:
service:
version: 1.0.0
nacos:
host: 127.0.0.1
port: 8848
10 changes: 10 additions & 0 deletions spring-boot-dubbo-nacos/sample-api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http:https://www.w3.org/2001/XMLSchema-instance"
xmlns="http:https://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http:https://maven.apache.org/POM/4.0.0 http:https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.itmuch.dubbo</groupId>
<artifactId>sample-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.itmuch.dubbo;

public interface DemoService {

String sayHello(String name);

}

0 comments on commit c922a97

Please sign in to comment.