Commit 83ce353d by HanChao

dubbo 项目 demo

parents
<?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">
<parent>
<artifactId>industry-cloud-parent</artifactId>
<groupId>org.gzicloud.industry</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>client-api</artifactId>
<dependencies>
<dependency>
<groupId>org.gzicloud.industry</groupId>
<artifactId>client-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.gzicloud.industry</groupId>
<artifactId>client-facade</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.gzicloud.industry.client.api;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
public class ClientApiApplication {
public static void main(String[] args) {
SpringApplication.run(ClientApiApplication.class, args);
}
}
package com.gzicloud.industry.client.api.controller;
import com.gzicloud.industry.client.facade.service.ITestService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/test")
public class TestController {
@DubboReference
private ITestService resumeService;
@GetMapping("/simple")
public String simple(String id) {
return resumeService.test(Long.valueOf(id));
}
@GetMapping("/simple1")
public String simple1(String id) {
return "测试:" + id;
}
}
server:
port: 11001
spring:
cloud:
nacos:
discovery:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
config:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置
file-extension: yml #默认properties
dubbo:
protocol:
# dubbo 协议
name: dubbo
# dubbo 协议端口( -1 表示自增端口,从 20880 开始)
port: -1
host: 127.0.0.1
registry:
# 挂载到 Spring Cloud 注册中心
address: spring-cloud://localhost
cloud:
# 订阅服务提供方的应用列表,订阅多个服务提供者使用 "," 连接
subscribed-services: industry-client-resume-server
server:
port: 8003
spring:
application:
name: industry-client-api
cloud:
nacos:
discovery:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
config:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置
file-extension: yml #默认properties
\ No newline at end of file
server:
port: 8003
spring:
application:
name: industry-client-api
cloud:
nacos:
discovery:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
config:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置
file-extension: yml #默认properties
\ No newline at end of file
spring:
profiles:
active: dev
application:
name: industry-client-api
\ No newline at end of file
<?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">
<parent>
<artifactId>industry-cloud-parent</artifactId>
<groupId>org.gzicloud.industry</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>client-common</artifactId>
</project>
\ No newline at end of file
//package com.gzicloud.industry.client.common.service;
//
//public interface ITestService {
//
// // facade
// String test(Long id);
//
//}
<?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">
<parent>
<artifactId>industry-cloud-parent</artifactId>
<groupId>org.gzicloud.industry</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>client-facade</artifactId>
</project>
\ No newline at end of file
package com.gzicloud.industry.client.facade.service;
public interface ITestService {
String test(Long id);
}
<?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">
<parent>
<artifactId>industry-cloud-parent</artifactId>
<groupId>org.gzicloud.industry</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>client-resume-server</artifactId>
<properties>
<mybatis-plus.version>3.4.1</mybatis-plus.version>
</properties>
<dependencies>
<dependency>
<groupId>org.gzicloud.industry</groupId>
<artifactId>client-common</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.gzicloud.industry</groupId>
<artifactId>client-facade</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- MyBatis-Plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<version>${mybatis-plus.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>mysql</groupId>-->
<!-- <artifactId>mysql-connector-java</artifactId>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->
<!-- -->
</dependencies>
</project>
\ No newline at end of file
package com.gzicloud.industry.client.resume;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@EnableDiscoveryClient
@SpringBootApplication
public class ClientResumeApplication {
public static void main(String[] args) {
SpringApplication.run(ClientResumeApplication.class, args);
}
}
package com.gzicloud.industry.client.resume.dao;
public interface ResumeMapper {
}
package com.gzicloud.industry.client.resume.dubbo;
import com.gzicloud.industry.client.facade.service.ITestService;
import com.gzicloud.industry.client.resume.service.IResumeService;
import org.apache.dubbo.config.annotation.DubboService;
import javax.annotation.Resource;
@DubboService
public class TestServiceImpl implements ITestService {
@Resource
private IResumeService resumeService;
@Override
public String test(Long id) {
return resumeService.getName(id) + " + dubbo中返回的";
}
}
package com.gzicloud.industry.client.resume.service;
public interface IResumeService {
String getName(Long id);
}
package com.gzicloud.industry.client.resume.service.impl;
import com.gzicloud.industry.client.resume.service.IResumeService;
import org.springframework.stereotype.Service;
@Service
public class ResumeServiceImpl implements IResumeService {
@Override
public String getName(Long id) {
return "spring bean 类中返回的:" + id;
}
}
spring:
application:
name: industry-client-resume-server
cloud:
nacos:
discovery:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
config:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置
file-extension: yml #默认properties
datasource:
hikari:
jdbc-url: jdbc:mysql://localhost:3306/db2020?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowMultiQueries=true&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true
username: hanchao
password: 123123
driver-class-name: com.mysql.cj.jdbc.Driver
minimum-idle: 10
maximum-pool-size: 20
connection-timeout: 2000
dubbo:
scan:
# dubbo 服务扫描基准包
base-packages: com.gzicloud.industry.client.resume
protocol:
# dubbo 协议
name: dubbo
# dubbo 协议端口( -1 表示自增端口,从 20880 开始)
port: -1
host: 127.0.0.1
registry:
# 挂载到 Spring Cloud 的注册中心
address: spring-cloud://localhost
\ No newline at end of file
server:
port: 8003
spring:
application:
name: industry-client-resume-server
cloud:
nacos:
discovery:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
config:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置
file-extension: yml #默认properties
\ No newline at end of file
server:
port: 8003
spring:
application:
name: industry-client-resume-server
cloud:
nacos:
discovery:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
config:
server-addr: localhost:8848 #Nacos 链接地址
namespace: 2fe44b66-8b9b-4df7-ae48-b8763132c498 #Nacos 命名空间ID
group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置
file-extension: yml #默认properties
\ No newline at end of file
spring:
profiles:
active: dev
application:
name: industry-client-resume-server
\ No newline at end of file
<?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>
<groupId>org.gzicloud.industry</groupId>
<artifactId>industry-cloud-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>client-common</module>
<module>client-api</module>
<module>client-resume-server</module>
<module>client-facade</module>
</modules>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.6</version>
<relativePath/>
</parent>
<properties>
<java.version>11</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring-cloud.version>2020.0.3</spring-cloud.version>
<spring-cloud-alibaba.version>2021.1</spring-cloud-alibaba.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>${spring-cloud-alibaba.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-dubbo</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.csp</groupId>
<artifactId>sentinel-apache-dubbo-adapter</artifactId>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>11</source>
<target>11</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>maven-releases</id>
<url>http://gyy.jqlink.tech/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<url>http://gyy.jqlink.tech/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<repositories>
<repository>
<id>local-nexus-maven-public</id>
<url>http://gyy.jqlink.tech/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local-nexus-maven-public</id>
<url>http://gyy.jqlink.tech/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
\ 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