Initial commit
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>cn.lingniu.framework</groupId>
|
||||
<artifactId>lingniu-framework-dependencies</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../../lingniu-framework-dependencies/pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>lingniu-framework-plugin-microservice-nacos</artifactId>
|
||||
<name>lingniu-framework-plugin-microservice-nacos</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>nacos-client</artifactId>
|
||||
<groupId>com.alibaba.nacos</groupId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.lingniu.framework</groupId>
|
||||
<artifactId>lingniu-framework-plugin-core</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.lingniu.framework</groupId>
|
||||
<artifactId>lingniu-framework-plugin-microservice-common</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.reactivex</groupId>
|
||||
<artifactId>rxjava</artifactId>
|
||||
<version>1.3.8</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,72 @@
|
||||
# 框架核心web应用模块
|
||||
|
||||
|
||||
## 概述 (Overview)
|
||||
|
||||
1. 定位: 基于 Alibaba Nacos 封装,支持服务注册、发现、多中心注册等功能的自动化组件
|
||||
2. 核心能力:
|
||||
* 支持多中心注册与服务发现
|
||||
3. 适用场景:
|
||||
* 公司内部微服务统一注册中心
|
||||
* 与 FeignClient 配合实现服务间调用
|
||||
|
||||
|
||||
## 如何配置
|
||||
|
||||
```yaml
|
||||
spring:
|
||||
application:
|
||||
name: lingniu-framework-demo
|
||||
profiles:
|
||||
active: dev
|
||||
cloud:
|
||||
nacos:
|
||||
enabled: true #开启微服务自定义注册,自动获取当前框架信息,启动时间等到metadata中
|
||||
discovery:
|
||||
server-addr: http://nacos-uat-new-inter.xx.net.cn:8848 #注册中心地址
|
||||
username: nacos_test #注册中心用户名
|
||||
password: nacos_test #注册中心密码
|
||||
|
||||
```
|
||||
|
||||
|
||||
## 接口提供端
|
||||
|
||||
```java
|
||||
@RestController
|
||||
@RequestMapping
|
||||
public class GithubApiController {
|
||||
|
||||
@GetMapping("/repos/{owner}/{repo}/contributors")
|
||||
public CommonResult<List<Contributor>> contributors(@PathVariable("owner") String owner, @PathVariable("repo") String repo) {
|
||||
// 模拟返回贡献者列表
|
||||
Contributor contributor1 = new Contributor("user1", 10);
|
||||
Contributor contributor2 = new Contributor("user2", 5);
|
||||
List<Contributor> response = new ArrayList<>();
|
||||
response.add(contributor1);
|
||||
response.add(contributor2);
|
||||
return CommonResult.success(response);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 接口调用方
|
||||
|
||||
```java
|
||||
// name = 接口提供方的应用名
|
||||
@FeignClient(name = "lingniu-framework-provider-demo"
|
||||
//外部接口配置url: @FeignClient(name = "github-api", url = "https://api.github.com"
|
||||
// 方式1 配置fallback
|
||||
// , fallback = GithubApiClientFallBack.class
|
||||
// 方式2 配置fallbackFactory
|
||||
// , fallbackFactory = GithubApiClientFallbackFactory.class
|
||||
)
|
||||
public interface DemoFeignClient {
|
||||
|
||||
@GetMapping("/repos/{owner}/{repo}/contributors")
|
||||
CommonResult<List<Contributor>> contributors(@PathVariable("owner") String owner, @PathVariable("repo") String repo);
|
||||
|
||||
@GetMapping("/reposNotFound")
|
||||
CommonResult<List<Contributor>> reposNotFound(@RequestParam("owner") String owner, @RequestParam("repo") String repo);
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user