mirror of
https://github.com/chatopera/cosin.git
synced 2025-08-01 16:38:02 +08:00
parent
5fa30be7c6
commit
29d7756959
@ -1 +1,2 @@
|
||||
#!/usr/bin/env sh
|
||||
cd ./cskefu-frontend && pnpm run lint
|
@ -15,6 +15,7 @@ services:
|
||||
volumes:
|
||||
- ./mysql/data:/var/lib/mysql
|
||||
- ./mysql/nacos.sql:/docker-entrypoint-initdb.d/nacos.sql
|
||||
- ./mysql/v9.init.sql:/docker-entrypoint-initdb.d/v9.init.sql
|
||||
command: --max_allowed_packet=32505856
|
||||
|
||||
# https://hub.docker.com/r/nacos/nacos-server
|
||||
@ -109,40 +110,8 @@ services:
|
||||
- ./openresty/certs:/certs
|
||||
- ./openresty/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf
|
||||
depends_on:
|
||||
- cskefu-web-gateway
|
||||
- cskefu-websocket-service
|
||||
|
||||
cskefu-web-gateway:
|
||||
image: cskefu/cskefu-web-gateway
|
||||
# container_name: cskefu-web-gateway
|
||||
restart: always
|
||||
# ports:
|
||||
# - "${CSKEFU_WEB_GATEWAY_PORT:-8080}:8080"
|
||||
expose:
|
||||
- 8080
|
||||
volumes:
|
||||
- ./cskefu/logs:/cskefu/logs
|
||||
- ./bootstrap.properties:/app/resources/bootstrap.properties
|
||||
- ./logback-spring.xml:/app/resources/logback-spring.xml
|
||||
deploy:
|
||||
replicas: 3
|
||||
environment:
|
||||
- "JAVA_OPTS=-Xmx${CSKEFU_JAVA_XMX:-512m} -Xms${CSKEFU_JAVA_XMS:-512m} -XX:PermSize=128m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true --add-opens java.base/jdk.internal.misc=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true --illegal-access=warn"
|
||||
- LOGGING_LEVEL_ROOT=${LOGGING_LEVEL_ROOT:-INFO}
|
||||
- SPRING_APPLICATION_NAME=cskefu-web-gateway
|
||||
- SPRING_DATASOURCE_URL=jdbc:mysql://mysql:3306/cskefu?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=GMT%2B8
|
||||
- SPRING_DATASOURCE_USERNAME=root
|
||||
- SPRING_DATASOURCE_PASSWORD=${DB_PASSWD:-123456}
|
||||
# - SPRING_DATASOURCE_HIKARI_MAXIMUM_POOL_SIZE=100
|
||||
- SPRING_DATA_REDIS_HOST=redis
|
||||
- SPRING_DATA_REDIS_PORT=6379
|
||||
- SPRING_RABBITMQ_ADDRESSES=rabbitmq
|
||||
- SPRING_RABBITMQ_PORT=${RABBITMQ_CLIENT_PORT:-5672}
|
||||
- SPRING_CLOUD_NACOS_DISCOVERY_SERVER_ADDR=nacos:8848
|
||||
depends_on:
|
||||
- cskefu-auth-service
|
||||
- cskefu-manager-service
|
||||
|
||||
cskefu-manager-service:
|
||||
image: cskefu/cskefu-manager-service
|
||||
# container_name: cskefu-manager-service
|
||||
|
@ -21,143 +21,57 @@ http {
|
||||
|
||||
#keepalive_timeout 0;
|
||||
keepalive_timeout 65;
|
||||
|
||||
#gzip on;
|
||||
|
||||
init_by_lua_block {
|
||||
instanceQueue = {}
|
||||
instance_map = {}
|
||||
balancer = require "ngx.balancer"
|
||||
nkeys = require "table.nkeys"
|
||||
cjson = require "cjson"
|
||||
}
|
||||
|
||||
upstream cskefu_web_gateway {
|
||||
server 0.0.0.1;
|
||||
balancer_by_lua_block {
|
||||
local balancer = require "ngx.balancer"
|
||||
local instance = table.remove(instanceQueue, 1)
|
||||
local ok, err = balancer.set_current_peer(instance["ip"], instance["port"])
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "failed to set the current peer: ", err)
|
||||
return ngx.exit(500)
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
upstream cskefu_websocket_service {
|
||||
server 0.0.0.1;
|
||||
balancer_by_lua_block {
|
||||
local balancer = require "ngx.balancer"
|
||||
local instance = table.remove(instanceQueue, 1)
|
||||
local ok, err = balancer.set_current_peer(instance["ip"], instance["port"])
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "failed to set the current peer: ", err)
|
||||
return ngx.exit(500)
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
server {
|
||||
root /usr/share/nginx/html;
|
||||
client_max_body_size 100M;
|
||||
|
||||
location /api/ {
|
||||
location ~* /api/.*?/(.*) {
|
||||
access_by_lua_block {
|
||||
local prefix = ngx.var.uri:match("^/api/([^/]+)/")
|
||||
local service_name = 'cskefu-'..prefix..'-service'
|
||||
local cjson = require "cjson"
|
||||
local queueLength = table.getn(instanceQueue)
|
||||
if not instance_map[service_name] then
|
||||
instance_map[service_name] = {}
|
||||
end
|
||||
local queue_length = table.nkeys(instance_map[service_name])
|
||||
local mapper = {}
|
||||
if queueLength > 0 then
|
||||
for i = 1, queueLength do
|
||||
local id = instanceQueue[i]["ip"]..":"..instanceQueue[i]["port"]
|
||||
mapper[id] = i
|
||||
end
|
||||
for i = 1, queue_length do
|
||||
mapper[instance_map[service_name][i]["ip"]..":"..instance_map[service_name][i]["port"]] = i
|
||||
end
|
||||
local result = ngx.location.capture("/nacos", {args='serviceName=cskefu-web-gateway'})
|
||||
local result = ngx.location.capture("/nacos", {args='serviceName='..service_name})
|
||||
local hosts = cjson.decode(result.body)['hosts']
|
||||
local hostsLength = table.getn(hosts)
|
||||
local others = {}
|
||||
instanceQueue = {}
|
||||
for i = 1, hostsLength do
|
||||
local id = hosts[i]["ip"]..":"..hosts[i]["port"]
|
||||
if hosts[i]["healthy"] == true then
|
||||
if mapper[id] then
|
||||
instanceQueue[mapper[id]] = {
|
||||
["ip"] = hosts[i]["ip"],
|
||||
["port"] = hosts[i]["port"]
|
||||
}
|
||||
else
|
||||
table.insert(others, {
|
||||
["ip"] = hosts[i]["ip"],
|
||||
["port"] = hosts[i]["port"]
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
local othersLength = table.getn(others)
|
||||
if othersLength > 0 then
|
||||
for i = 1, othersLength do
|
||||
table.insert(instanceQueue, {
|
||||
["ip"] = others[i]["ip"],
|
||||
["port"] = others[i]["port"]
|
||||
|
||||
local hosts_length = table.nkeys(hosts)
|
||||
for i = 1, hosts_length do
|
||||
if not mapper[hosts[i]["ip"]..":"..hosts[i]["port"]] then
|
||||
table.insert(instance_map[service_name], {
|
||||
["ip"] = hosts[i]["ip"],
|
||||
["port"] = hosts[i]["port"]
|
||||
})
|
||||
end
|
||||
end
|
||||
local instance = table.remove(instance_map[service_name], 1)
|
||||
ngx.ctx.host = instance["ip"]
|
||||
ngx.ctx.port = instance["port"]
|
||||
}
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
# proxy_pass http://cskefu-web-gateway:8080/;
|
||||
proxy_pass http://cskefu_web_gateway/;
|
||||
}
|
||||
proxy_pass http://cskefu-upstream/$1;
|
||||
|
||||
location /ws/ {
|
||||
access_by_lua_block {
|
||||
local cjson = require "cjson"
|
||||
local queueLength = table.getn(instanceQueue)
|
||||
local mapper = {}
|
||||
if queueLength > 0 then
|
||||
for i = 1, queueLength do
|
||||
local id = instanceQueue[i]["ip"]..":"..instanceQueue[i]["port"]
|
||||
mapper[id] = i
|
||||
end
|
||||
end
|
||||
local result = ngx.location.capture("/nacos", {args='serviceName=cskefu-websocket-service'})
|
||||
local hosts = cjson.decode(result.body)['hosts']
|
||||
local hostsLength = table.getn(hosts)
|
||||
local others = {}
|
||||
instanceQueue = {}
|
||||
for i = 1, hostsLength do
|
||||
local id = hosts[i]["ip"]..":"..hosts[i]["port"]
|
||||
if hosts[i]["healthy"] == true then
|
||||
if mapper[id] then
|
||||
instanceQueue[mapper[id]] = {
|
||||
["ip"] = hosts[i]["ip"],
|
||||
["port"] = hosts[i]["port"]
|
||||
}
|
||||
else
|
||||
table.insert(others, {
|
||||
["ip"] = hosts[i]["ip"],
|
||||
["port"] = hosts[i]["port"]
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
local othersLength = table.getn(others)
|
||||
if othersLength > 0 then
|
||||
for i = 1, othersLength do
|
||||
table.insert(instanceQueue, {
|
||||
["ip"] = others[i]["ip"],
|
||||
["port"] = others[i]["port"]
|
||||
})
|
||||
end
|
||||
end
|
||||
}
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $host;
|
||||
proxy_http_version 1.1;
|
||||
# proxy_pass http://cskefu-websocket-service:10000/ws/;
|
||||
proxy_pass http://cskefu_websocket_service;
|
||||
}
|
||||
|
||||
location = /nacos {
|
||||
@ -167,6 +81,17 @@ http {
|
||||
}
|
||||
}
|
||||
|
||||
upstream cskefu-upstream {
|
||||
server 0.0.0.1;
|
||||
balancer_by_lua_block {
|
||||
local ok, err = balancer.set_current_peer(ngx.ctx.host, ngx.ctx.port)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "failed to set the current peer: ", err)
|
||||
return ngx.exit(500)
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
# Don't reveal OpenResty version to clients.
|
||||
# server_tokens off;
|
||||
}
|
||||
|
@ -56,21 +56,23 @@ contact-backend
|
||||
│ │
|
||||
│ └─cskefu-assistant-mvc mvc相关辅助模块
|
||||
│
|
||||
├─cskefu-auth 认证和鉴权,不要随意添加更多微服务
|
||||
├─cskefu-auth 认证和鉴权,不要随意添加微服务
|
||||
│ │
|
||||
│ ├─cskefu-auth-domain
|
||||
│ │
|
||||
│ └─cskefu-auth-service
|
||||
│
|
||||
├─cskefu-channel 渠道接入,可根据需要添加更多微服务
|
||||
├─cskefu-channel 渠道接入,不同渠道用不同的,不要随意添加微服务
|
||||
│ │
|
||||
│ ├─cskefu-channel-wechat-domain
|
||||
│ ├─cskefu-channel-service xxx渠道微服务,目录以cskefu-channel-开头
|
||||
│ │
|
||||
│ ├─cskefu-channel-wechat-service 微信渠道接入
|
||||
│ ├─cskefu-channel-wechat-domain 微信渠道
|
||||
│ │
|
||||
│ ├─cskefu-channel-xxx-domain
|
||||
│ ├─cskefu-channel-wechat 微信渠道业务逻辑
|
||||
│ │
|
||||
│ └─cskefu-channel-xxx-service xxx渠道微服务,目录以cskefu-channel-开头
|
||||
│ ├─cskefu-channel-xxx-domain xxx微信渠道
|
||||
│ │
|
||||
│ └─cskefu-channel-xxx xxx渠道业务逻辑
|
||||
│
|
||||
├─cskefu-manager 核心控制,如基础配置、时效管理、会话分配,不要随意添加更多服务
|
||||
│ │
|
||||
@ -84,10 +86,6 @@ contact-backend
|
||||
│ │
|
||||
│ └─cskefu-plugin-service
|
||||
│
|
||||
├─cskefu-gateway 聚合网关服务放在这个目录下
|
||||
│ │
|
||||
│ └─cskefu-web-gateway 暴漏给web端的聚合网关,web前端只和这一个服务交互(WebSocket连接除外),其他微服务提供基础功能,聚合网关组合调用其他微服务的接口
|
||||
│
|
||||
└─cskefu-websocket
|
||||
│
|
||||
├─cskefu-websocket-domain
|
||||
|
@ -2,7 +2,7 @@
|
||||
<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">
|
||||
<artifactId>cskefu-channel-wechat-service</artifactId>
|
||||
<artifactId>cskefu-channel-service</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<modelVersion>4.0.0</modelVersion>
|
@ -14,7 +14,7 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modules>
|
||||
<module>cskefu-channel-wechat-service</module>
|
||||
<module>cskefu-channel-service</module>
|
||||
<module>cskefu-channel-wechat-domain</module>
|
||||
</modules>
|
||||
</project>
|
@ -1,73 +0,0 @@
|
||||
<?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">
|
||||
<artifactId>cskefu-web-gateway</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>cskefu-web-gateway</name>
|
||||
<url>https://www.cskefu.com/</url>
|
||||
<parent>
|
||||
<groupId>com.cskefu</groupId>
|
||||
<artifactId>cskefu-backend</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bootstrap</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cskefu</groupId>
|
||||
<artifactId>cskefu-assistant-mvc</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.cskefu</groupId>
|
||||
<artifactId>cskefu-backend</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.github.shalousun</groupId>
|
||||
<artifactId>smart-doc-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.google.cloud.tools</groupId>
|
||||
<artifactId>jib-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
@ -1,34 +0,0 @@
|
||||
package com.cskefu;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@RestController
|
||||
@RefreshScope
|
||||
public class CskefuWebGatewayApplication {
|
||||
@Value("${xxx}")
|
||||
private String xxx;
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
SpringApplication.run(CskefuWebGatewayApplication.class, args);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping({"", "/"})
|
||||
public String index() throws UnknownHostException {
|
||||
InetAddress localHost = InetAddress.getLocalHost();
|
||||
return localHost.getHostAddress() + " " + xxx;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
debug=true
|
||||
server.port=8080
|
||||
spring.application.name=cskefu-web-gateway
|
||||
|
||||
spring.mvc.static-path-pattern=/smart-doc/**
|
||||
spring.web.resources.static-locations=classpath:/smart-doc
|
||||
|
||||
spring.cloud.nacos.discovery.server-addr=localhost:8848
|
||||
|
||||
# sentinel
|
||||
spring.cloud.sentinel.transport.dashboard=localhost:9850
|
||||
spring.cloud.sentinel.transport.port=9851
|
||||
|
||||
spring.cloud.nacos.config.import-check.enabled=false
|
||||
|
||||
xxx=aaaaaaaaaa
|
@ -1,16 +0,0 @@
|
||||
nacos.namespace=cskefu
|
||||
nacos.server-addr=nacos:8848
|
||||
|
||||
spring.cloud.nacos.discovery.server-addr=${nacos.server-addr}
|
||||
spring.cloud.nacos.discovery.namespace=${nacos.namespace}
|
||||
|
||||
spring.cloud.nacos.config.server-addr=${nacos.server-addr}
|
||||
spring.cloud.nacos.config.file-extension=json
|
||||
spring.cloud.nacos.config.namespace=${nacos.namespace}
|
||||
spring.cloud.nacos.config.group=${nacos.namespace}-default
|
||||
|
||||
spring.cloud.nacos.config.extension-configs[0].group=${nacos.namespace}-default
|
||||
spring.cloud.nacos.config.extension-configs[0].data_id=common
|
||||
spring.cloud.nacos.config.extension-configs[0].refresh=true
|
||||
|
||||
spring.config.import=optional:nacos:${spring.cloud.nacos.config.extension-configs[0].data_id}.${spring.cloud.nacos.config.file-extension},optional:nacos:@spring.application.name@.${spring.cloud.nacos.config.file-extension}
|
@ -1,17 +0,0 @@
|
||||
{
|
||||
"serverUrl": "http://localhost:8080",
|
||||
"pathPrefix": "",
|
||||
"allInOne": true,
|
||||
"outPath": "src/main/resources/smart-doc",
|
||||
"style": "xt256",
|
||||
"createDebugPage": false,
|
||||
"revisionLogs": [
|
||||
{
|
||||
"version": "1.0",
|
||||
"revisionTime": "2023-09-13",
|
||||
"status": "创建",
|
||||
"author": "lecjy",
|
||||
"remarks": "春松客服接口文档"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
<?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">
|
||||
<artifactId>cskefu-gateway</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<name>cskefu-gateway</name>
|
||||
<url>https://www.cskefu.com/</url>
|
||||
<parent>
|
||||
<groupId>com.cskefu</groupId>
|
||||
<artifactId>cskefu-backend</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modules>
|
||||
<module>cskefu-web-gateway</module>
|
||||
</modules>
|
||||
</project>
|
@ -23,7 +23,6 @@
|
||||
<module>cskefu-assistant-module</module>
|
||||
<module>cskefu-auth</module>
|
||||
<module>cskefu-channel</module>
|
||||
<module>cskefu-gateway</module>
|
||||
<module>cskefu-manager</module>
|
||||
<module>cskefu-plugin</module>
|
||||
<module>cskefu-websocket</module>
|
||||
|
Loading…
x
Reference in New Issue
Block a user