forked from yudaocode/SpringBoot-Labs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
YunaiV
committed
Apr 26, 2020
1 parent
85328ff
commit 7fad871
Showing
15 changed files
with
379 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?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>lab-30</artifactId> | ||
<groupId>cn.iocoder.springboot.labs</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>lab-30-dubbo-annotations-sentinel</artifactId> | ||
<packaging>pom</packaging> | ||
<modules> | ||
<module>user-rpc-service-api-04</module> | ||
<module>user-rpc-service-provider-04</module> | ||
<module>user-rpc-service-consumer-04</module> | ||
</modules> | ||
|
||
|
||
</project> |
15 changes: 15 additions & 0 deletions
15
lab-30/lab-30-dubbo-annotations-sentinel/user-rpc-service-api-04/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?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>lab-30-dubbo-annotations-demo</artifactId> | ||
<groupId>cn.iocoder.springboot.labs</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>user-rpc-service-api-04</artifactId> | ||
|
||
|
||
</project> |
18 changes: 18 additions & 0 deletions
18
...-rpc-service-api-04/src/main/java/cn/iocoder/springboot/lab30/rpc/api/UserRpcService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cn.iocoder.springboot.lab30.rpc.api; | ||
|
||
import cn.iocoder.springboot.lab30.rpc.dto.UserDTO; | ||
|
||
/** | ||
* 用户服务 RPC Service 接口 | ||
*/ | ||
public interface UserRpcService { | ||
|
||
/** | ||
* 根据指定用户编号,获得用户信息 | ||
* | ||
* @param id 用户编号 | ||
* @return 用户信息 | ||
*/ | ||
UserDTO get(Integer id); | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...el/user-rpc-service-api-04/src/main/java/cn/iocoder/springboot/lab30/rpc/dto/UserDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cn.iocoder.springboot.lab30.rpc.dto; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* 用户信息 DTO | ||
*/ | ||
public class UserDTO implements Serializable { | ||
|
||
/** | ||
* 用户编号 | ||
*/ | ||
private Integer id; | ||
/** | ||
* 昵称 | ||
*/ | ||
private String name; | ||
/** | ||
* 性别 | ||
*/ | ||
private Integer gender; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public UserDTO setId(Integer id) { | ||
this.id = id; | ||
return this; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public UserDTO setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
public Integer getGender() { | ||
return gender; | ||
} | ||
|
||
public UserDTO setGender(Integer gender) { | ||
this.gender = gender; | ||
return this; | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
lab-30/lab-30-dubbo-annotations-sentinel/user-rpc-service-consumer-04/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?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> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.1.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>user-rpc-service-consumer-04</artifactId> | ||
|
||
<dependencies> | ||
<!-- 引入定义的 Dubbo API 接口 --> | ||
<dependency> | ||
<groupId>cn.iocoder.springboot.labs</groupId> | ||
<artifactId>user-rpc-service-api-04</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<!-- 引入 Spring Boot 依赖 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- 实现对 Dubbo 的自动化配置 --> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo</artifactId> | ||
<version>2.7.4.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-spring-boot-starter</artifactId> | ||
<version>2.7.4.1</version> | ||
</dependency> | ||
|
||
<!-- 使用 Zookeeper 作为注册中心 --> | ||
<dependency> | ||
<groupId>org.apache.curator</groupId> | ||
<artifactId>curator-framework</artifactId> | ||
<version>2.13.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.curator</groupId> | ||
<artifactId>curator-recipes</artifactId> | ||
<version>2.13.0</version> | ||
</dependency> | ||
|
||
<!-- Sentinel 核心库 --> | ||
<dependency> | ||
<groupId>com.alibaba.csp</groupId> | ||
<artifactId>sentinel-core</artifactId> | ||
<version>1.7.1</version> | ||
</dependency> | ||
<!-- Sentinel 接入控制台 --> | ||
<dependency> | ||
<groupId>com.alibaba.csp</groupId> | ||
<artifactId>sentinel-transport-simple-http</artifactId> | ||
<version>1.7.1</version> | ||
</dependency> | ||
<!-- Sentinel 对 Dubbo 的支持 --> | ||
<dependency> | ||
<groupId>com.alibaba.csp</groupId> | ||
<artifactId>sentinel-apache-dubbo-adapter</artifactId> | ||
<version>1.7.1</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
38 changes: 38 additions & 0 deletions
38
...ervice-consumer-04/src/main/java/cn/iocoder/springboot/lab30/rpc/ConsumerApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package cn.iocoder.springboot.lab30.rpc; | ||
|
||
import cn.iocoder.springboot.lab30.rpc.api.UserRpcService; | ||
import cn.iocoder.springboot.lab30.rpc.dto.UserDTO; | ||
import org.apache.dubbo.config.annotation.Reference; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
import org.springframework.stereotype.Component; | ||
|
||
@SpringBootApplication | ||
public class ConsumerApplication { | ||
|
||
public static void main(String[] args) { | ||
// 启动 Spring Boot 应用 | ||
ConfigurableApplicationContext context = SpringApplication.run(ConsumerApplication.class, args); | ||
} | ||
|
||
@Component | ||
public class UserRpcServiceTest implements CommandLineRunner { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
@Reference(version = "${dubbo.consumer.UserRpcService.version}") | ||
private UserRpcService userRpcService; | ||
|
||
@Override | ||
public void run(String... args) throws Exception { | ||
UserDTO user = userRpcService.get(1); | ||
logger.info("[run][发起一次 Dubbo RPC 请求,获得用户为({})", user); | ||
} | ||
|
||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...-consumer-04/src/main/java/cn/iocoder/springboot/lab30/rpc/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package cn.iocoder.springboot.lab30.rpc.controller; | ||
|
||
import cn.iocoder.springboot.lab30.rpc.api.UserRpcService; | ||
import cn.iocoder.springboot.lab30.rpc.dto.UserDTO; | ||
import org.apache.dubbo.config.annotation.Reference; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/user") | ||
public class UserController { | ||
|
||
@Reference(version = "${dubbo.consumer.UserRpcService.version}") | ||
private UserRpcService userRpcService; | ||
|
||
@GetMapping("/get") | ||
public UserDTO get(@RequestParam("id") Integer id) { | ||
return userRpcService.get(id); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...bbo-annotations-sentinel/user-rpc-service-consumer-04/src/main/resources/application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# dubbo 配置项,对应 DubboConfigurationProperties 配置类 | ||
dubbo: | ||
# Dubbo 应用配置 | ||
application: | ||
name: user-service-consumer # 应用名 | ||
# Dubbo 注册中心配置 | ||
registry: | ||
address: zookeeper://127.0.0.1:2181 # 注册中心地址。个鞥多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。 | ||
# Dubbo 消费者配置 | ||
consumer: | ||
timeout: 1000 # 【重要】远程服务调用超时时间,单位:毫秒。默认为 1000 毫秒,胖友可以根据自己业务修改 | ||
UserRpcService: | ||
version: 1.0.0 |
1 change: 1 addition & 0 deletions
1
...-annotations-sentinel/user-rpc-service-consumer-04/src/main/resources/sentinel.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
csp.sentinel.dashboard.server=127.0.0.1:7070 |
74 changes: 74 additions & 0 deletions
74
lab-30/lab-30-dubbo-annotations-sentinel/user-rpc-service-provider-04/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?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> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.2.1.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>user-rpc-service-provider-04</artifactId> | ||
|
||
<dependencies> | ||
<!-- 引入定义的 Dubbo API 接口 --> | ||
<dependency> | ||
<groupId>cn.iocoder.springboot.labs</groupId> | ||
<artifactId>user-rpc-service-api-04</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<!-- 引入 Spring Boot 依赖 --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter</artifactId> | ||
</dependency> | ||
|
||
<!-- 实现对 Dubbo 的自动化配置 --> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo</artifactId> | ||
<version>2.7.4.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-spring-boot-starter</artifactId> | ||
<version>2.7.4.1</version> | ||
</dependency> | ||
|
||
<!-- 使用 Zookeeper 作为注册中心 --> | ||
<dependency> | ||
<groupId>org.apache.curator</groupId> | ||
<artifactId>curator-framework</artifactId> | ||
<version>2.13.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.curator</groupId> | ||
<artifactId>curator-recipes</artifactId> | ||
<version>2.13.0</version> | ||
</dependency> | ||
|
||
<!-- Sentinel 核心库 --> | ||
<dependency> | ||
<groupId>com.alibaba.csp</groupId> | ||
<artifactId>sentinel-core</artifactId> | ||
<version>1.7.1</version> | ||
</dependency> | ||
<!-- Sentinel 接入控制台 --> | ||
<dependency> | ||
<groupId>com.alibaba.csp</groupId> | ||
<artifactId>sentinel-transport-simple-http</artifactId> | ||
<version>1.7.1</version> | ||
</dependency> | ||
<!-- Sentinel 对 Dubbo 的支持 --> | ||
<dependency> | ||
<groupId>com.alibaba.csp</groupId> | ||
<artifactId>sentinel-apache-dubbo-adapter</artifactId> | ||
<version>1.7.1</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
14 changes: 14 additions & 0 deletions
14
...ervice-provider-04/src/main/java/cn/iocoder/springboot/lab30/rpc/ProviderApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package cn.iocoder.springboot.lab30.rpc; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class ProviderApplication { | ||
|
||
public static void main(String[] args) { | ||
// 启动 Spring Boot 应用 | ||
SpringApplication.run(ProviderApplication.class, args); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
...provider-04/src/main/java/cn/iocoder/springboot/lab30/rpc/service/UserRpcServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cn.iocoder.springboot.lab30.rpc.service; | ||
|
||
import cn.iocoder.springboot.lab30.rpc.api.UserRpcService; | ||
import cn.iocoder.springboot.lab30.rpc.dto.UserDTO; | ||
import org.apache.dubbo.config.annotation.Service; | ||
|
||
@Service(version = "${dubbo.provider.UserRpcService.version}") | ||
public class UserRpcServiceImpl implements UserRpcService { | ||
|
||
@Override | ||
public UserDTO get(Integer id) { | ||
return new UserDTO().setId(id) | ||
.setName("没有昵称:" + id) | ||
.setGender(id % 2 + 1); // 1 - 男;2 - 女 | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...bbo-annotations-sentinel/user-rpc-service-provider-04/src/main/resources/application.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# dubbo 配置项,对应 DubboConfigurationProperties 配置类 | ||
dubbo: | ||
# Dubbo 应用配置 | ||
application: | ||
name: user-service-provider # 应用名 | ||
# Dubbo 注册中心配 | ||
registry: | ||
address: zookeeper://127.0.0.1:2181 # 注册中心地址。个鞥多注册中心,可见 http://dubbo.apache.org/zh-cn/docs/user/references/registry/introduction.html 文档。 | ||
# Dubbo 服务提供者协议配置 | ||
protocol: | ||
port: -1 # 协议端口。使用 -1 表示随机端口。 | ||
name: dubbo # 使用 `dubbo://` 协议。更多协议,可见 http://dubbo.apache.org/zh-cn/docs/user/references/protocol/introduction.html 文档 | ||
# Dubbo 服务提供者配置 | ||
provider: | ||
timeout: 1000 # 【重要】远程服务调用超时时间,单位:毫秒。默认为 1000 毫秒,胖友可以根据自己业务修改 | ||
UserRpcService: | ||
version: 1.0.0 | ||
# 配置扫描 Dubbo 自定义的 @Service 注解,暴露成 Dubbo 服务提供者 | ||
scan: | ||
base-packages: cn.iocoder.springboot.lab30.rpc.service |
1 change: 1 addition & 0 deletions
1
...-annotations-sentinel/user-rpc-service-provider-04/src/main/resources/sentinel.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
csp.sentinel.dashboard.server=127.0.0.1:7070 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters