Commit fcf0e5f4 by QIANGLU

add dubbo demo

parent c7f701ab
......@@ -10,6 +10,39 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>consumer</artifactId>
<properties>
<revision>2.7.5</revision>
</properties>
<dependencies>
<dependency>
<groupId>com.matrix</groupId>
<artifactId>dubbo-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.5</version>
</dependency>
<!-- Zookeeper dependencies -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>2.7.5</version>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
\ No newline at end of file
</project>
\ No newline at end of file
package com.matrix.grpc;
package com.matrix.dubbo.consumer;
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
......@@ -8,11 +9,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @author qianglu
*/
@SpringBootApplication
public class PureStartup {
@EnableDubboConfig
public class ConsumerStartup {
public static void main(String[] args) {
SpringApplication.run(PureStartup.class, args);
SpringApplication.run(ConsumerStartup.class, args);
}
}
package com.matrix.dubbo.provider.controller;
package com.matrix.dubbo.consumer.controller;
import com.matrix.dubbo.api.DemoService;
import com.matrix.dubbo.consumer.service.ConsumerService;
import com.matrix.dubbo.consumer.service.ConsumerServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -13,14 +15,14 @@ import javax.annotation.Resource;
* @Version 1.0
*/
@RestController
@RequestMapping("/provider")
public class DemoController {
@RequestMapping("/consumer")
public class ConusmerController {
@Resource
private DemoService demoService;
private ConsumerService consumerService;
@RequestMapping("/demo")
public String getDemo() {
return demoService.getDemo();
return consumerService.getConsumer();
}
}
......@@ -7,4 +7,6 @@ package com.matrix.dubbo.consumer.service;
* @Version 1.0
*/
public interface ConsumerService {
public String getConsumer();
}
package com.matrix.dubbo.consumer.service;
import com.matrix.dubbo.api.DemoService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
/**
* @ClassName ConsumerService
* @Author QIANGLU
* @Date 2020/2/4 4:03 下午
* @Version 1.0
*/
public class ConsumerService {
@Service
public class ConsumerServiceImpl implements ConsumerService {
@Reference(version = "${demo.service.version}" ,check = false)
private DemoService demoService;
@Override
public String getConsumer() {
return demoService.getDemo();
}
}
spring:
application:
name: learn-pure
name: consumer
server:
port: 6080
port: 6081
dubbo:
protocol:
name: dubbo
port: 11135
registry:
address: zookeeper://127.0.0.1:2181
scan:
base-packages: com.matrix.dubbo
demo:
service:
version: 1.0
\ No newline at end of file
......@@ -2,14 +2,9 @@
<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>spring-boot-dubbo</artifactId>
<groupId>com.nova</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.matrix</groupId>
<artifactId>dubbo-api</artifactId>
<version>1.0-SNAPSHOT</version>
</project>
\ No newline at end of file
......@@ -6,5 +6,7 @@ package com.matrix.dubbo.api;
* @Date 2020/2/4 3:30 下午
* @Version 1.0
*/
public class DemoService {
public interface DemoService {
String getDemo();
}
......@@ -6,7 +6,13 @@
<groupId>com.nova</groupId>
<artifactId>spring-boot-dubbo</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>consumer</module>
<module>provider</module>
<module>dubbo-api</module>
</modules>
<parent>
<artifactId>matrix</artifactId>
......@@ -16,25 +22,17 @@
<properties>
<java.version>1.8</java.version>
<dubbo.version>2.7.0</dubbo.version>
</properties>
<dependencies>
<dependency>
<groupId>com.secoo.mall</groupId>
<artifactId>logger-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</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-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......
......@@ -2,14 +2,44 @@
<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>
<artifactId>spring-boot-dubbo</artifactId>
<groupId>com.nova</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>provider</artifactId>
<dependencies>
<dependency>
<groupId>com.matrix</groupId>
<artifactId>dubbo-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>2.7.5</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>2.7.5</version>
</dependency>
<!-- Zookeeper dependencies -->
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>
<version>2.7.5</version>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.spring.boot.demo.provider.bootstrap;
package com.matrix.dubbo.provider;
import org.apache.zookeeper.server.ServerConfig;
......
package com.matrix.dubbo.consumer;
package com.matrix.dubbo.provider;
import org.apache.dubbo.config.spring.context.annotation.EnableDubboConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.core.env.Environment;
/**
* @author qianglu
*/
@SpringBootApplication
public class ConsumerStartup {
@EnableDubboConfig
public class ProviderStartup {
public static void main(String[] args) {
SpringApplication.run(ConsumerStartup.class, args);
new SpringApplicationBuilder(ProviderStartup.class)
.listeners((ApplicationListener<ApplicationEnvironmentPreparedEvent>) event -> {
Environment environment = event.getEnvironment();
new EmbeddedZooKeeper(2181, false).start();
})
.run(args);
}
}
package com.matrix.dubbo.provider.service;
import com.matrix.dubbo.api.DemoService;
import org.apache.dubbo.config.annotation.Service;
import javax.annotation.Resource;
/**
* @ClassName DemoServiceImpl
* @Author QIANGLU
* @Date 2020/2/4 3:29 下午
* @Version 1.0
*/
public class DemoServiceImpl {
@Service(version = "1.0")
public class DemoProviderServiceImpl implements DemoService{
@Override
public String getDemo() {
return "this is provider";
}
}
spring:
application:
name: consumer
name: provider
server:
port: 6080
dubbo:
protocol:
name: dubbo
port: 11134
registry:
address: zookeeper://127.0.0.1:2181
scan:
base-packages: com.matrix.dubbo.provider.service
demo:
service:
version: 1.0
embedded:
zookeeper:
port: 2181
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment