# yfcloud-repo-example
**Repository Path**: darlinLiu/yfcloud-repo-example
## Basic Information
- **Project Name**: yfcloud-repo-example
- **Description**: 组件库范例
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: 1.1.0-dev
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 2
- **Created**: 2023-02-06
- **Last Updated**: 2023-02-06
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# yfcloud-repo-example
## 一、快速上手 quick-start
#### 1. 启动范例项目
* 组件库范例仓库地址:https://gitee.com/yfclouds/yfcloud-repo-example/
* 定位启动类:com.yifeng.repo.example.ApplicationStartUp
* 设置启动参数
```text
-Dserver.port=8081
-Dapp_id=yfcloud-example
-Dapp_stage=develop
-Dapp_ver=1.0.0
-Dapp_conf=http://139.9.50.212:8848
-Dconf_username=test_dev
-Dconf_password=******(mask)
-Dspring.cloud.bootstrap.enabled=true
-Dlog.local.debug=true
温馨提示:请使用自己申请的帐号密码来启动。
```
* 在Nacos配置启动参数
```text
write.url=jdbc:mysql://192.168.254.37:59003/yfcloud_example?allowMultiQueries=true&serverTimezone=Asia/Shanghai
write.user=yfcloud_example
write.password=******(mask)
温馨提示:请使用自己申请的帐号密码来写数据库。
```
* 启动服务后就可以发起请求(更多的在api模块的resources目录下的*.http文件里面)
```http request
### 分页查询菜单数据,根据appId查询
GET http://127.0.0.1:8081/yfcloud-example/rpc/rpcSys/list?appId=2
```
* 关于日志时区问题
```text
最佳方案是设置服务器时区:TZ=Asia/Shanghai
```
## 二、框架库 frameworks
| 编号 | 名称 | 功能 | 说明 |
| :----: |:-----------------------------:| :----: | :---- |
| 1 | frameworks-base | 框架基础 | Base 是核心模块,提供最基础的框架能力 |
| 2 | frameworks-mybatis-starter | Mybatis+Mybatis plus增强 | Mybatis 提供数据层的应用能力 |
| 3 | frameworks-interfaces-starter | 接口工程 | Interface 提供接口管理能力 |
| 4 | frameworks-fsm-starter | 状态机 | FSM 提供状态机能力 |
| 5 | frameworks-xml-excel | 操作excel | EXCEL 提供Excel报表数据导入导出能力 |
| 6 | frameworks-redis-starter | redis分布式缓存 | 支持通过注解和命令的方式操作缓存 |
* 框架库仓库地址:https://gitee.com/yfclouds/frameworks/
* 温馨提示:超级外援提供的的是2.0.9-dev,基础产品研发适配益丰的版本是2.0.9.yf.2
## 三、组件库 yfcloud-repo
| 编号 | 名称 | 功能 | 说明 |
| :----: | :----: | :----: |:-------------------------------------------------------------------|
| 1 | yfcloud-base-parent | 基础pom | 新建项目建议继承该parent作为pom基础 |
| 2 | yfcloud-base-utils | 基础工具类 | 整合多年沉淀积累的工具类 |
| 3 | yfcloud-micro-service-starter-server | 微服务服务端starter | 新建项目建议依赖该starter作为服务端项目基础,
当前已经支持OSS、SSO、MPS、消息中心、
以及批量读和写多源数据库 |
| 4 | yfcloud-storage-starter-redis | redis分布式缓存 | 支持轻量级直接操作redis,建议使用frameworks-redis-starter |
| 5 | yfcloud-storage-starter-elasticsearch | ES搜索 | ES搜索的常用操作的最佳实践 |
| 6 | yfcloud-storage-starter-clickhouse | CK分析型数据库 | 未完成 |
| 7 | yfcloud-service-gateway-traffic | 业务网关流量控制 | 入口流量和出口流量管控 |
| 8 | yfcloud-service-gateway-request | 业务网关通用请求 | 通用http request抽象 | |
| 9 | yfcloud-stream-starter-mq | stream 消息队列中间件 | 支持RocketMQ和RabbitMQ | |
* 组件库仓库地址:https://gitee.com/yfclouds/yfcloud-repo/
* 温馨提示:基础产品研发自己积累的组件库,当前版本是1.0.0-dev
## 四、组件库范例 yfcloud-repo-example
### 1. 范例项目架构
* 服务端Server
* 客户端client
### 2. RPC请求规范
* RPC接口需要定义单独的url地址,安全控制保障仅内部微服务之间调用
### 3. 拦截器
* 支持通过Springboot拦截器获取请求header数据
### 4. 代码生成
* 支持多种模式生成代码:部分覆盖、全部覆盖、个性化覆盖,建议使用全部覆盖结合idea的版本管理来合并代码
* 接口文档支持smart-doc
### 5. 上传excel并解析数据
* 支持多种方式解析excel
```text
处理Java类:com.yifeng.repo.example.sys.controller.SysFileController
请求脚本:yfcloud-example-api/src/main/resources/http/SysFile.http
```
### 6. 消息队列
* 支持多种消息队列使用场景:削峰填谷、异步、解耦
* 事务消息、顺序消息、延时消息、广播消息
```text
测试代码:com.yifeng.repo.example.demo.mq.StreamMqTest
yaml配置样本:yfcloud-example-server\src\main\resources\bak
```
## 五、补充内容
### 1. 范例项目配套课件材料
* [《SQL语句打印插件》](https://yifeng.yuque.com/ko40cp/mnkea5/sm4dtlvtybrr48u1)
* [《技术框架2.0第七课:通用参数校验》](https://yifeng.yuque.com/ko40cp/mnkea5/ymfn4f)
* [《技术框架2.0第六课:日志管理》](https://yifeng.yuque.com/ko40cp/mnkea5/sazisv)
* [《技术框架2.0第五课:接口管理》](https://yifeng.yuque.com/ko40cp/mnkea5/lix60c)
* [《技术框架2.0第四课:消息队列》](https://yifeng.yuque.com/ko40cp/mnkea5/tlrrf8)
* [《技术框架2.0第三课:分布式缓存》](https://yifeng.yuque.com/ko40cp/mnkea5/mua6d7)
* [《技术框架2.0第二课:多功能查询》](https://yifeng.yuque.com/ko40cp/mnkea5/wl3fke)
* [《技术框架2.0第一课:起航》](https://yifeng.yuque.com/ko40cp/mnkea5/atteku)
* [《Java后台设计开发规范2.0版本》](https://yifeng.yuque.com/ko40cp/mnkea5/elluvl)
* [《技术框架2.0-OpenTalk》](https://yifeng.yuque.com/ko40cp/mnkea5/frofan)
* [《新技术框架汇报》](https://yifeng.yuque.com/ko40cp/mnkea5/craa9x)
### 2. 如果发现同一个组件两个版本,可以检查版本依赖关系
```text
查看依赖关系: mvn -Dverbose dependency:tree
```
### 3. jar模式调整为war模式
新项目建议大家使用Gitlab+Zadig,这样就不需要调整为war模式了。
#### 1. 在server模块的pom.xml调整打包模式
```xml
war
```
#### 2. 在server模块的pom.xml排除内置tomcat
```xml
com.yifeng.repo
yfcloud-micro-service-starter-server
org.springframework.boot
spring-boot-starter-tomcat
```
#### 3. 在server模块的pom.xml排除spring-boot-maven-plugin
```xml
org.springframework.boot
spring-boot-maven-plugin
${spring-boot-dependencies.version}
true
true
true
repackage
```
#### 4. 在server模块的pom.xml引入war打包插件
```xml
org.apache.maven.plugins
maven-war-plugin
3.2.2
```
#### 5. 在server模块的ApplicationStartUp重写启动方法
```java
@EnableMybatis
@SpringBootApplication
public class ApplicationStartUp extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ApplicationStartUp.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(ApplicationStartUp.class);
}
}
```
#### 6. 如果启动发现没有打印日志的解决建议
```text
1. 在application.yml中配置的 logging.config: classpath:logback-spring.xml
2. 检查类方法:org.springframework.boot.context.logging.LoggingApplicationListener#initializeSystem
String logConfig = StringUtils.trimWhitespace(environment.getProperty(CONFIG_PROPERTY));
3. 断点跟踪检查logConfig的实际获取值,如果返回错误的值就表示没有获取到日志配置地址,也就是不能打印日志
正确:classpath:logback-spring.xml
错误:-Djava.util.logging.config.file="C:\Users\00115\AppData\Local\JetBrains\IntelliJIdea2020.1\tomcat\Unnamed_yfcloud-transport\conf\logging.properties"
4. 解决方案:启动参数加上 -Dlogging.config=classpath:logback-spring.xml
```
### 4. 仓库地址
* 发布库:[Release](http://nexus.pharmacyyf.com/repository/maven-releases/)
* 快照库:[Snapshot](http://nexus.pharmacyyf.com/repository/maven-snapshots/)
* 私服仓库地址
```xml
pharmacyyf-release
Pharmacyyf Nexus Release
http://nexus.pharmacyyf.com/repository/maven-releases/
pharmacyyf-snapshot
Pharmacyyf Nexus Snapshot
http://nexus.pharmacyyf.com/repository/maven-snapshots/
true
always
warn
```
* maven settings 配置
对源仓库(pharmacyyf-release、pharmacyyf-snapshot)配置访问参数,如下可供参考:
```xml
pharmacyyf-release
******
******
pharmacyyf-snapshot
******
******
```
调整仓库镜像,将https://repo1.maven.org/maven2替换为如下的配置
```xml
central
central
http://nexus.pharmacyyf.com/repository/Central_maven/
central
```