增加集成Dubbo的demo
This commit is contained in:
@@ -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