微服务框架介绍
李国平 2017/6/18 java
[TOC]
# 目录结构说明
├── ith-boot-starter # starter预配置通用组件
│ ├── db-ith-boot-starter # 数据库
│ ├── ith-spring-boot-starter# 对业务微服务 通用预配置
│ ├── mq-ith-boot-starter # mq消息组件
│ ├── redis-ith-boot-starter # redis组件
│ └── shiro-ith-boot-starter # 用户会话组件
├── ith-service-gateway # 服务网关
├── ith-service-system # 基本业务服务
├── ith-service-auth # 登录认证授权服务
├── ith-service-file # 文件上传存储服务(支持OSS)
├── ith-common # 通用的jar
│ │── ith-common-core # 核心jar
│ └── ith-common-domain # 通用的 model enum dto (如:用户当前会话对象类在该jar中)
├── ith-service-xxx # 其他业务微服务中心
│ ├── xxx-web # 微服务主入口 依赖:xxx-service
│ ├── xxx-service # 业务逻辑层 依赖:xxx-dao
│ ├── xxx-dao # 数据库持久层 mappen.xml 和 接口类 依赖:xxx-domain
│ ├── xxx-domain # model、dto、enum 都放在这 领域层
│ ├── xxx-common # 只用于该服务下通用处理类
│ └── xxx-api # 调用其他微服务的 openfiegn 接口调用 依赖:xxx-domain
# 业务服务结构说明
├── xxx-api # 调用其他业务微服务
│ ├── com # 第一级包名(统一的)
│ │ ├── itonghui # 第二级包名(统一的)
│ │ │ ├── xxx # 第三级包名(统一使用该业务微服务名)
│ │ │ │ ├── openfeign # 第四级包名(统一的,里面放一些需要调用其他服务的feign接口)
│ │ │ │ │ ├── xxx # 第五级包名(以其他业务服务名为包名,里面放interface接口)
├── xxx-common # 该服务下通用处理类
│ ├── com # 第一级包名(统一的)
│ │ ├── itonghui # 第二级包名(统一的)
│ │ │ ├── xxx # 第三级包名(统一使用该业务微服务名)
│ │ │ │ ├── constant # 第四级包名(统一的)
│ │ │ │ │ ├── xxx # 第五级包名(以各个功能为包名,里面放置常量和返回状态等通用处理类)
├── xxx-dao # 数据库持久层
│ ├── com # 第一级包名(统一的)
│ │ ├── itonghui # 第二级包名(统一的)
│ │ │ ├── xxx # 第三级包名(统一使用该业务微服务名)
│ │ │ │ ├── xxx # 第四级包名(以各个功能为包名)
│ │ │ │ │ ├── dao # 第五级包名(统一的,放置接口和xml文件)
│ │ │ │ │ │ ├── mapper # 第六级包名(统一的,里面放置mapper.xml文件)
├── xxx-domain # model、dto、enum 都放在这 领域层
│ ├── com # 第一级包名(统一的)
│ │ ├── itonghui # 第二级包名(统一的)
│ │ │ ├── xxx # 第三级包名(统一使用该业务微服务名)
│ │ │ │ ├── xxx # 第四级包名(各个功能为包名)
│ │ │ │ │ ├── dto # 第五级包名(统一的)
│ │ │ │ │ ├── enums # 第五级包名(统一的)
│ │ │ │ │ ├── model # 第五级包名(统一的)
│ │ │ ├── xxxfeign # 第三级包名(统一使用该业务微服务名+feign标识)
│ │ │ │ ├── xxx # 第四级包名(以其他业务服务名为包名)
│ │ │ │ │ ├── dto # 第五级包名(统一的)
│ │ │ │ │ ├── enums # 第五级包名(统一的)
│ │ │ │ │ ├── model # 第五级包名(统一的)
├── xxx-service # 业务逻辑层
│ ├── com # 第一级包名(统一的)
│ │ ├── itonghui # 第二级包名(统一的)
│ │ │ ├── xxx # 第三级包名(统一使用该业务微服务名)
│ │ │ │ ├── xxx # 第四级包名(以各个功能为包名)
│ │ │ │ │ ├── business # 第五级包名(统一的,放置biz逻辑接口和biz逻辑实现类)
│ │ │ │ │ │ ├── impl # 第六级包名(统一的,里面放置biz逻辑实现类)
│ │ │ │ │ ├── service # 第五级包名(统一的,放置service接口和service实现类)
│ │ │ │ │ │ ├── impl # 第六级包名(统一的,里面放置service实现类)
├── xxx-web # 微服务主入口
│ ├── com # 第一级包名(统一的)
│ │ ├── itonghui # 第二级包名(统一的)
│ │ │ ├── xxx # 第三级包名(统一使用该业务微服务名)
│ │ │ │ ├── web # 第四级包名(统一的)
│ │ │ │ │ ├── xxx # 第五级包名(以各个功能为包名,各功能的Controller)
│ │ │ │ │ ├── feign # 第五级包名(统一的,放置本服务的feign类)
web下面有个resources包,放置一些枚举、返回状态、校验的国际化
├── resources
│ ├── res # 第一级包名(统一的)
│ │ ├── i18n # 第二级包名(统一的)
│ │ │ ├── enums # 第三级包名(统一的)
# 英文国际化:命名格式为 功能名称+EnumsMessage_en.properties
# 中文国际化:命名格式为 功能名称+EnumsMessage_zh_CN.properties
│ │ │ ├── resp # 第三级包名(统一的)
# 英文国际化:命名格式为 功能名称+RespMessage_en.properties
# 中文国际化:命名格式为 功能名称+RespMessage_zh_CN.properties
│ │ │ ├── validation # 第三级包名(统一的)
# 英文国际化:命名格式为 功能名称+ValiMessages_en.properties
# 中文国际化:命名格式为 功能名称+ValiMessages_zh_CN.properties
# 例子:
xxx - api

xxx - common

xxx - dao

xxx - domain

xxx - service

xxx - web

# API接口URL定义规则
public class ApiUrlConstant {
/** 公开接口 ex:/api/{你的服务名}/{业务功能名} */
public static final String API = "/api";
/** 会话验证 会员接口 ex:/api/member/{你的服务名}/{业务功能名} */
public static final String API_MEMBER = API + "/member";
/** 会话验证 管理接口 ex:/api/admin/{你的服务名}/{业务功能名} */
public static final String API_ADMIN = API + "/admin";
/** 会话验证 通用接口 ex:/api/authen/{你的服务名}/{业务功能名} */
public static final String API_AUTH = API + "/authen";
}
# “bootstrap.yml” 配置文件说明
server:
port: 8083 #服务启动端口
spring:
application:
name: ith-service-system #服务名称 命名规范 ith-service-{你的服务名称小写}
profiles:
active: dev # 运行环境 (dev 开发环境,text测试环境,prod生产环境)
cloud:
nacos:
server-addr: 192.168.0.196:10002 # nacos 服务注册中心 地址
discovery:
group: DEFAULT_GROUP # 服务发现分组 openfeign 远程调用通过分组进行隔离 调用自己组的服务
config: # 配置文件
file-extension: yaml # 配置文件后缀名
shared-configs: #通用配置文件
- ith-service-datasource-${spring.profiles.active}.yaml # 数据库配置文件
- ith-service-redis-${spring.profiles.active}.yaml # redis配置文件
- sentinel-${spring.profiles.active}.yaml # 限流熔断配置文件
- zipkin-${spring.profiles.active}.yaml # 全链路跟踪配置文件
management:
endpoints:
web:
exposure:
include: '*' # 默认配置加上 用于中间件服务 发现监控统计数据
在各自的微服务中可以添加自己的配置文件,在nacos 的配置中心里添加配置文件 ,
文件命名规则:“bootstrap.yml” 里的 ${spring.application.name}-${spring.profiles.active}.yaml 的组合
示例:“ith-service-system-dev.yaml”