增加集成Dubbo的demo
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
## Demo说明
|
||||
|
||||
Spring Cloud 集成 Dubbo 的 demo
|
||||
|
||||
启动后访问:http://127.0.0.1:8091/test/abc
|
||||
|
||||
|
||||
|
||||
## 集成 Spring Cloud Gateway
|
||||
[Dubbo想要个网关怎么办?试试整合Spring Cloud Gateway](https://mp.weixin.qq.com/s/_idYl39i1eQejLLLlCW2sg)
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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.zlt</groupId>
|
||||
<artifactId>zlt-demo</artifactId>
|
||||
<version>4.2.0</version>
|
||||
</parent>
|
||||
<artifactId>dubbo-demo</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-log-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-dubbo</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.zlt;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2020/1/30
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication
|
||||
public class WebDubboApp {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WebDubboApp.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.zlt.controller;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.zlt.service.RpcService;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2020/6/26
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
public class WebController {
|
||||
@DubboReference
|
||||
private RpcService dubboService;
|
||||
|
||||
@GetMapping("/test/{p}")
|
||||
public String test(@PathVariable("p") String param) {
|
||||
log.info("==============WebController");
|
||||
return dubboService.test(param);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.zlt.service;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2020/1/30
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
public interface RpcService {
|
||||
String test(String param);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.zlt.service.impl;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.zlt.service.RpcService;
|
||||
|
||||
/**
|
||||
* @author zlt
|
||||
* @date 2020/1/30
|
||||
* <p>
|
||||
* Blog: https://zlt2000.gitee.io
|
||||
* Github: https://github.com/zlt2000
|
||||
*/
|
||||
@Slf4j
|
||||
@DubboService(protocol = "dubbo")
|
||||
public class RpcServiceImpl implements RpcService {
|
||||
@Override
|
||||
public String test(String param) {
|
||||
log.info("==============RpcServiceImpl");
|
||||
return "dubbo service: " + param;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
dubbo:
|
||||
scan:
|
||||
base-packages: org.zlt.service
|
||||
protocols:
|
||||
dubbo:
|
||||
name: dubbo
|
||||
port: -1
|
||||
registry:
|
||||
address: spring-cloud://localhost
|
||||
consumer:
|
||||
timeout: 5000
|
||||
check: false
|
||||
retries: 0
|
||||
cloud:
|
||||
subscribed-services:
|
||||
|
||||
zlt:
|
||||
trace:
|
||||
enable: true
|
||||
@@ -0,0 +1,11 @@
|
||||
server:
|
||||
port: 8091
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: zlt-web-dubbo
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
cloud:
|
||||
nacos:
|
||||
server-addr: 192.168.28.130:8848
|
||||
Reference in New Issue
Block a user