Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
janrs-io committed Jun 1, 2023
1 parent fb544b7 commit e71525e
Show file tree
Hide file tree
Showing 142 changed files with 2,510 additions and 3,779 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

本项目基于 https://github.com/janrs-io/Jgrpc 微服务最佳实践写的几个案例。基本包含了开发中会需要用到的实践代码,包含以下:

- 使用 `reids` 作为缓存以及实现鉴权和白名单[放弃使用jwt]
- 使用 `gorm` 作为 `ORM`
- 使用 `dtm` 作为事务处理
- 使用 `grpc-gateway-middleware-v2` 作为中间件
- 统一的 `grpc` 返回以及自动解析到 `http`
- 使用了 `istio` 的外部扩展鉴权[可以做token鉴权以及rbac鉴权和接口白名单]
- 实现了 `otel` 收集链路信息上报到 `jeager`
- 实现了 `otel` 将链路数据上报到 `ELK`

除了提供基于 `grpc-gateway` 开发微服务的案例代码外,还有基于 `Gitlab/Jenkins/Harbor/K8s``DevOps``DevOps`
流程可以参考我的博客,地址:https://janrs.com/category/cicd/
Expand All @@ -26,12 +27,9 @@

# 已开发以下功能

## `auth` 鉴权服务
## `istio` 外部扩展 `ext-authz` 鉴权服务

- 注册授权功能
- 删除授权功能
- 刷新授权功能
- 获取授权功能
- token 鉴权功能
- 接口白名单功能

## `user` 用户服务
Expand All @@ -51,9 +49,15 @@

## `order` 订单服务

- 添加订单功能 [增加了 `DTM` 事务支持。创建订单会使用 `DTM``SAGA` 事务扣除产品库存并且绕过 `auth` 白名单鉴权]
- 添加订单功能 [增加了 `DTM` 事务支持。创建订单会使用 `DTM``SAGA` 事务扣除产品库存]
- 获取订单详情功能

---

## 链路截图

![img.png](img.png)
![img_1.png](img_1.png)
![img_2.png](img_2.png)

**如果觉得对你的学习有帮助,点个 `star`**
3 changes: 3 additions & 0 deletions devops/auth/dev/Deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# deployment

apiVersion: apps/v1
kind: Deployment
metadata:
name: auth
namespace: rgrpc-dev
labels:
app: auth
version: v1.0
spec:
replicas: 1
selector:
Expand All @@ -15,6 +17,7 @@ spec:
metadata:
labels:
app: auth
version: v1.0
spec:
imagePullSecrets:
- name: registry-secret
Expand Down
2 changes: 1 addition & 1 deletion devops/auth/dev/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pipeline{
environment {

// Harbor Mirror Center Address
REGISTRY_URL = "registry.your-domain.com:11223"
REGISTRY_URL = "registry.your-domain.com:1134"

// Project Project Name
PROJECT_NAME = "rgrpc-dev"
Expand Down
25 changes: 11 additions & 14 deletions devops/auth/dev/Service.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
# service
# auth service
apiVersion: v1
kind: Service
metadata:
name: auth-http
name: auth
namespace: rgrpc-dev
labels:
app: auth
version: "1.0"
spec:
type: ClusterIP
selector:
app: auth
ports:
# http 服务
- port: 9001
protocol: TCP
name: http
targetPort: 9001
---
# service
apiVersion: v1
kind: Service
metadata:
name: auth-grpc
namespace: rgrpc-dev
spec:
type: ClusterIP
selector:
app: auth
ports:
appProtocol: http
# grpc 服务
- port: 50051
protocol: TCP
name: grpc
targetPort: 50051
appProtocol: grpc
38 changes: 22 additions & 16 deletions devops/auth/dev/configmap/authservice-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ http:
name: "auth-http"
# database config
database:
driver: mysql # Database Drivers
host: 192.168.1.36 # Host
port: 3306 # Port
username: john # Username
password: password # Password
database: rgrpc-user # Database
charset: utf8mb4 # Charset
maxIdleCons: 10 # Maximum number of connections in the idle connection pool
maxOpenCons: 100 # Maximum number of open database connections
logMode: info # Log level
enableFileLogWriter: true # Whether to enable log files
logFilename: sql.log # Log file name
mysql:
host: 192.168.1.36 # Host
port: 3306 # Port
username: john # Username
password: 123456 # Password
database: rgrpc-user # Database
charset: utf8mb4 # Charset
maxIdleCons: 10 # Maximum number of connections in the idle connection pool
maxOpenCons: 100 # Maximum number of open database connections
logMode: info # Log level
enableFileLogWriter: true # Whether to enable log files
logFilename: sql.log # Log file name

# redis config
redis:
host: 192.168.1.36
port: ":6379"
username: "default"
password: "password"
password: "123456"
database: 0
dial_timeout: 10s
read_timeout: 10s
Expand All @@ -46,7 +46,13 @@ logger:
# whiteList 权限白名单
whiteList:
api:
- "/proto.v1.UserService/Login"
- "/proto.v1.UserService/Register"
# user 用户服务接口白名单
- "/user.v1.login"
- "/user.v1.register"
permission:
- ""
- ""

# otel trace 链路追踪配置
trace:
serviceName: "auth-service"
endPoint: "otel-collector.otel:4317"
4 changes: 2 additions & 2 deletions devops/auth/test/configmap/authservice-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ database:
host: 192.168.1.36 # Host
port: 3306 # Port
username: john # Username
password: password # Password
password: 123456 # Password
database: rgrpc-user # Database
charset: utf8mb4 # Charset
maxIdleCons: 10 # Maximum number of connections in the idle connection pool
Expand All @@ -29,7 +29,7 @@ redis:
host: 192.168.1.36
port: ":6379"
username: "default"
password: "password"
password: "123456"
database: 0
dial_timeout: 10s
read_timeout: 10s
Expand Down
2 changes: 2 additions & 0 deletions devops/order/dev/Deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ metadata:
namespace: rgrpc-dev
labels:
app: order
version: v1.0
spec:
replicas: 1
selector:
Expand All @@ -15,6 +16,7 @@ spec:
metadata:
labels:
app: order
version: v1.0
spec:
imagePullSecrets:
- name: registry-secret
Expand Down
2 changes: 1 addition & 1 deletion devops/order/dev/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pipeline{
environment {

// Harbor Mirror Center Address
REGISTRY_URL = "registry.your-domain.com:11223"
REGISTRY_URL = "registry.your-domain.com:1134"

// Project Project Name
PROJECT_NAME = "rgrpc-dev"
Expand Down
25 changes: 11 additions & 14 deletions devops/order/dev/Service.yaml
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
# service
# order service
apiVersion: v1
kind: Service
metadata:
name: order-http
name: order
namespace: rgrpc-dev
labels:
app: order
version: "1.0"
spec:
type: ClusterIP
selector:
app: order
ports:
# http 服务
- port: 9001
protocol: TCP
name: http
appProtocol: http
targetPort: 9001
---
# service
apiVersion: v1
kind: Service
metadata:
name: order-grpc
namespace: rgrpc-dev
spec:
type: ClusterIP
selector:
app: order
ports:
# grpc 服务
- port: 50051
protocol: TCP
name: grpc
targetPort: 50051
appProtocol: grpc
39 changes: 21 additions & 18 deletions devops/order/dev/configmap/orderservice-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ http:

# database 数据库配置
database:
driver: mysql # Database Drivers
host: 192.168.1.36 # Host
port: 3306 # Port
username: john # Username
password: password # Password
database: rgrpc-order # Database
charset: utf8mb4 # Charset
maxIdleCons: 10 # Maximum number of connections in the idle connection pool
maxOpenCons: 100 # Maximum number of open database connections
logMode: info # Log level
enableFileLogWriter: true # Whether to enable log files
logFilename: sql.log # Log file name
mysql:
host: 192.168.1.36 # Host
port: 3306 # Port
username: john # Username
password: 123456 # Password
database: rgrpc-order # Database
charset: utf8mb4 # Charset
maxIdleCons: 10 # Maximum number of connections in the idle connection pool
maxOpenCons: 100 # Maximum number of open database connections
logMode: info # Log level
enableFileLogWriter: true # Whether to enable log files
logFilename: sql.log # Log file name

# redis 配置
redis:
host: 192.168.1.36
port: ":6379"
username: "default"
password: "password"
password: "123456"
database: 0
dial_timeout: 10s
read_timeout: 10s
Expand All @@ -40,9 +40,12 @@ redis:

# client 客户端配置
client:
# 权限客户端
authHost: auth-grpc
authPort: ":50051"
# product 产品服务客户端
productHost: product-grpc
productPort: ":50051"
productHost: product
productPort: ":50051"

# otel trace 链路追踪配置
trace:
tracerName: "order-service-tracer"
serviceName: "order-service"
endPoint: "otel-collector.otel:4317"
3 changes: 3 additions & 0 deletions devops/product/dev/Deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# deployment

apiVersion: apps/v1
kind: Deployment
metadata:
name: product
namespace: rgrpc-dev
labels:
app: product
version: v1.0
spec:
replicas: 1
selector:
Expand All @@ -15,6 +17,7 @@ spec:
metadata:
labels:
app: product
version: v1.0
spec:
imagePullSecrets:
- name: registry-secret
Expand Down
2 changes: 1 addition & 1 deletion devops/product/dev/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pipeline{
environment {

// Harbor Mirror Center Address
REGISTRY_URL = "registry.your-domain.com:11223"
REGISTRY_URL = "registry.your-domain.com:1134"

// Project Project Name
PROJECT_NAME = "rgrpc-dev"
Expand Down
26 changes: 11 additions & 15 deletions devops/product/dev/Service.yaml
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
# http service
# product service
apiVersion: v1
kind: Service
metadata:
name: product-http
name: product
namespace: rgrpc-dev
labels:
app: product
version: "1.0"
spec:
type: ClusterIP
selector:
app: product
ports:
# http 服务
- port: 9001
protocol: TCP
name: http
appProtocol: http
targetPort: 9001
---

# grpc service
apiVersion: v1
kind: Service
metadata:
name: product-grpc
namespace: rgrpc-dev
spec:
type: ClusterIP
selector:
app: product
ports:
# grpc 服务
- port: 50051
protocol: TCP
name: grpc
targetPort: 50051
appProtocol: grpc
Loading

0 comments on commit e71525e

Please sign in to comment.