feat: 完成Nacos配置优化和WebSocket集成

主要更新:
1. 统一所有微服务端口配置(19000-19008)
2. 为所有服务创建本地/测试/生产三套环境配置
3. 配置Nacos认证密码(本地:Peanut2817*#, 测试/生产:EmotionMuseum2025)
4. 优化网关路由配置,支持负载均衡和WebSocket
5. 新增emotion-websocket模块,支持实时聊天
6. 前端集成WebSocket,替代HTTP轮询
7. 添加配置验证和管理工具脚本

技术特性:
- 完整的环境隔离和服务发现
- WebSocket实时通信支持
- 负载均衡路由配置
- 跨域和安全配置
- 自动重连和心跳检测
This commit is contained in:
2025-07-17 18:10:45 +08:00
parent 9a3a8267b5
commit c77352877d
391 changed files with 46585 additions and 4294 deletions
@@ -1,106 +1,5 @@
server:
port: 19000
# 本地开发环境配置
spring:
application:
name: emotion-gateway
# Redis配置
data:
redis:
host: localhost
port: 6379
password:
database: 0
timeout: 10000ms
lettuce:
pool:
max-active: 8
max-wait: -1ms
max-idle: 8
min-idle: 0
# 网关配置
cloud:
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
# 用户服务路由
- id: emotion-user-route
uri: http://localhost:19001
predicates:
- Path=/user/**
filters:
- StripPrefix=0
# 验证码服务路由
- id: emotion-captcha-route
uri: http://localhost:19001
predicates:
- Path=/captcha/**
filters:
- StripPrefix=0
# OAuth服务路由
- id: emotion-oauth-route
uri: http://localhost:19001
predicates:
- Path=/oauth/**
filters:
- StripPrefix=0
# AI服务路由
- id: emotion-ai-route
uri: http://localhost:19002
predicates:
- Path=/ai/**
filters:
- StripPrefix=0
# 记录服务路由
- id: emotion-record-route
uri: http://localhost:19003
predicates:
- Path=/record/**
filters:
- StripPrefix=0
# 成长服务路由
- id: emotion-growth-route
uri: http://localhost:19004
predicates:
- Path=/growth/**
filters:
- StripPrefix=0
# 探索服务路由
- id: emotion-explore-route
uri: http://localhost:19005
predicates:
- Path=/explore/**
filters:
- StripPrefix=0
# 奖励服务路由
- id: emotion-reward-route
uri: http://localhost:19006
predicates:
- Path=/reward/**
filters:
- StripPrefix=0
# 统计服务路由
- id: emotion-stats-route
uri: http://localhost:19007
predicates:
- Path=/stats/**
filters:
- StripPrefix=0
# Nacos配置
spring:
cloud:
nacos:
@@ -109,7 +8,16 @@ spring:
namespace:
group: DEFAULT_GROUP
enabled: true
username: nacos
password: Peanut2817*#
metadata:
version: 1.0.0
zone: local
register-enabled: true
ephemeral: true
cluster-name: DEFAULT
service: ${spring.application.name}
weight: 1
heart-beat-interval: 5000
heart-beat-timeout: 15000
ip-delete-timeout: 30000
@@ -119,6 +27,118 @@ spring:
group: DEFAULT_GROUP
file-extension: yml
enabled: false
username: nacos
password: Peanut2817*#
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
# 全局跨域配置
globalcors:
cors-configurations:
'[/**]':
allowed-origins: "*"
allowed-methods: "*"
allowed-headers: "*"
allow-credentials: true
routes:
# 用户服务路由 (包含认证功能)
- id: emotion-user-route
uri: lb://emotion-user
predicates:
- Path=/user/**
filters:
- StripPrefix=0
# 验证码服务路由
- id: emotion-captcha-route
uri: lb://emotion-user
predicates:
- Path=/captcha/**
filters:
- StripPrefix=0
# OAuth服务路由
- id: emotion-oauth-route
uri: lb://emotion-user
predicates:
- Path=/oauth/**
filters:
- StripPrefix=0
# AI服务路由
- id: emotion-ai-route
uri: lb://emotion-ai
predicates:
- Path=/ai/**
filters:
- StripPrefix=0
# WebSocket聊天服务路由
- id: emotion-websocket-route
uri: lb://emotion-websocket
predicates:
- Path=/websocket/**
filters:
- StripPrefix=0
# WebSocket连接路由 (支持WebSocket升级)
- id: emotion-websocket-ws-route
uri: lb://emotion-websocket
predicates:
- Path=/ws/**
filters:
- StripPrefix=0
# 情绪记录服务路由
- id: emotion-record-route
uri: lb://emotion-record
predicates:
- Path=/record/**
filters:
- StripPrefix=0
# 成长课题服务路由
- id: emotion-growth-route
uri: lb://emotion-growth
predicates:
- Path=/growth/**
filters:
- StripPrefix=0
# 地图探索服务路由
- id: emotion-explore-route
uri: lb://emotion-explore
predicates:
- Path=/explore/**
filters:
- StripPrefix=0
# 成就奖励服务路由
- id: emotion-reward-route
uri: lb://emotion-reward
predicates:
- Path=/reward/**
filters:
- StripPrefix=0
# 统计分析服务路由
- id: emotion-stats-route
uri: lb://emotion-stats
predicates:
- Path=/stats/**
filters:
- StripPrefix=0
# Redis配置
data:
redis:
host: localhost
port: 6379
password:
database: 0
# 日志配置
logging:
@@ -126,20 +146,5 @@ logging:
com.emotionmuseum: debug
org.springframework.cloud.gateway: debug
org.springframework.web: debug
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{50} - %msg%n"
file: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{50} - %msg%n"
file:
name: logs/emotion-gateway-local.log
# 管理端点配置
management:
endpoints:
web:
exposure:
include: health,info,metrics,gateway
endpoint:
health:
show-details: always
gateway:
enabled: true
name: logs/emotion-gateway-local.log
@@ -1,105 +1,151 @@
server:
port: 9000
# 生产环境配置
spring:
application:
name: emotion-gateway
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
- org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
- com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration
data:
redis:
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}
database: 0
timeout: 3000ms
lettuce:
pool:
max-active: 20
max-idle: 10
min-idle: 5
max-wait: 3000ms
cloud:
nacos:
discovery:
server-addr: ${NACOS_SERVER_ADDR:localhost:8848}
namespace: public
server-addr: 47.111.10.27:8848
namespace: prod
group: DEFAULT_GROUP
enabled: true
ip: ${SERVER_IP:localhost}
username: nacos
password: EmotionMuseum2025
metadata:
version: 1.0.0
environment: prod
zone: prod
register-enabled: true
ephemeral: true
cluster-name: DEFAULT
service: ${spring.application.name}
weight: 1
heart-beat-interval: 5000
heart-beat-timeout: 15000
ip-delete-timeout: 30000
config:
server-addr: 47.111.10.27:8848
namespace: prod
group: DEFAULT_GROUP
file-extension: yml
enabled: false
username: nacos
password: EmotionMuseum2025
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
# 全局跨域配置
globalcors:
cors-configurations:
'[/**]':
allowed-origins: "*"
allowed-methods: "*"
allowed-headers: "*"
allow-credentials: true
routes:
# 用户服务路由
- id: emotion-user
# 用户服务路由 (包含认证功能)
- id: emotion-user-route
uri: lb://emotion-user
predicates:
- Path=/api/user/**
- Path=/user/**
filters:
- StripPrefix=0
# 验证码服务路由
- id: emotion-captcha-route
uri: lb://emotion-user
predicates:
- Path=/captcha/**
filters:
- StripPrefix=0
# OAuth服务路由
- id: emotion-oauth-route
uri: lb://emotion-user
predicates:
- Path=/oauth/**
filters:
- StripPrefix=0
# AI服务路由
- id: emotion-ai
- id: emotion-ai-route
uri: lb://emotion-ai
predicates:
- Path=/api/ai/**
# 记录服务路由
- id: emotion-record
- Path=/ai/**
filters:
- StripPrefix=0
# WebSocket聊天服务路由
- id: emotion-websocket-route
uri: lb://emotion-websocket
predicates:
- Path=/websocket/**
filters:
- StripPrefix=0
# WebSocket连接路由 (支持WebSocket升级)
- id: emotion-websocket-ws-route
uri: lb://emotion-websocket
predicates:
- Path=/ws/**
filters:
- StripPrefix=0
# 情绪记录服务路由
- id: emotion-record-route
uri: lb://emotion-record
predicates:
- Path=/api/record/**
- Path=/record/**
filters:
- StripPrefix=1
# 成长服务路由
- id: emotion-growth
- StripPrefix=0
# 成长课题服务路由
- id: emotion-growth-route
uri: lb://emotion-growth
predicates:
- Path=/api/growth/**
- Path=/growth/**
filters:
- StripPrefix=1
# 探索服务路由
- id: emotion-explore
- StripPrefix=0
# 地图探索服务路由
- id: emotion-explore-route
uri: lb://emotion-explore
predicates:
- Path=/api/explore/**
- Path=/explore/**
filters:
- StripPrefix=1
# 奖励服务路由
- id: emotion-reward
- StripPrefix=0
# 成就奖励服务路由
- id: emotion-reward-route
uri: lb://emotion-reward
predicates:
- Path=/api/reward/**
- Path=/reward/**
filters:
- StripPrefix=1
# 统计服务路由
- id: emotion-stats
- StripPrefix=0
# 统计分析服务路由
- id: emotion-stats-route
uri: lb://emotion-stats
predicates:
- Path=/api/stats/**
- Path=/stats/**
filters:
- StripPrefix=1
- StripPrefix=0
# Redis配置
data:
redis:
host: 47.111.10.27
port: 6379
password: EmotionMuseum2025*#
database: 0
# 日志配置
logging:
level:
com.emotionmuseum: INFO
org.springframework.cloud.gateway: DEBUG
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
# 管理端点
management:
endpoints:
web:
exposure:
include: health,info,gateway
endpoint:
health:
show-details: always
com.emotionmuseum: warn
org.springframework.cloud.gateway: warn
org.springframework.web: warn
com.alibaba.nacos: error
file:
name: logs/emotion-gateway-prod.log
@@ -0,0 +1,151 @@
# 测试环境配置
spring:
cloud:
nacos:
discovery:
server-addr: 47.111.10.27:8848
namespace: test
group: DEFAULT_GROUP
enabled: true
username: nacos
password: EmotionMuseum2025
metadata:
version: 1.0.0
zone: test
register-enabled: true
ephemeral: true
cluster-name: DEFAULT
service: ${spring.application.name}
weight: 1
heart-beat-interval: 5000
heart-beat-timeout: 15000
ip-delete-timeout: 30000
config:
server-addr: 47.111.10.27:8848
namespace: test
group: DEFAULT_GROUP
file-extension: yml
enabled: false
username: nacos
password: EmotionMuseum2025
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
# 全局跨域配置
globalcors:
cors-configurations:
"[/**]":
allowed-origins: "*"
allowed-methods: "*"
allowed-headers: "*"
allow-credentials: true
routes:
# 用户服务路由 (包含认证功能)
- id: emotion-user-route
uri: lb://emotion-user
predicates:
- Path=/user/**
filters:
- StripPrefix=0
# 验证码服务路由
- id: emotion-captcha-route
uri: lb://emotion-user
predicates:
- Path=/captcha/**
filters:
- StripPrefix=0
# OAuth服务路由
- id: emotion-oauth-route
uri: lb://emotion-user
predicates:
- Path=/oauth/**
filters:
- StripPrefix=0
# AI服务路由
- id: emotion-ai-route
uri: lb://emotion-ai
predicates:
- Path=/ai/**
filters:
- StripPrefix=0
# WebSocket聊天服务路由
- id: emotion-websocket-route
uri: lb://emotion-websocket
predicates:
- Path=/websocket/**
filters:
- StripPrefix=0
# WebSocket连接路由 (支持WebSocket升级)
- id: emotion-websocket-ws-route
uri: lb://emotion-websocket
predicates:
- Path=/ws/**
filters:
- StripPrefix=0
# 情绪记录服务路由
- id: emotion-record-route
uri: lb://emotion-record
predicates:
- Path=/record/**
filters:
- StripPrefix=0
# 成长课题服务路由
- id: emotion-growth-route
uri: lb://emotion-growth
predicates:
- Path=/growth/**
filters:
- StripPrefix=0
# 地图探索服务路由
- id: emotion-explore-route
uri: lb://emotion-explore
predicates:
- Path=/explore/**
filters:
- StripPrefix=0
# 成就奖励服务路由
- id: emotion-reward-route
uri: lb://emotion-reward
predicates:
- Path=/reward/**
filters:
- StripPrefix=0
# 统计分析服务路由
- id: emotion-stats-route
uri: lb://emotion-stats
predicates:
- Path=/stats/**
filters:
- StripPrefix=0
# Redis配置
data:
redis:
host: 47.111.10.27
port: 6379
password: EmotionMuseum2025*#
database: 0
# 日志配置
logging:
level:
com.emotionmuseum: info
org.springframework.cloud.gateway: info
org.springframework.web: info
com.alibaba.nacos: warn
file:
name: logs/emotion-gateway-test.log
@@ -4,40 +4,72 @@ server:
spring:
application:
name: emotion-gateway
# 配置文件激活
profiles:
active: dev
active: ${SPRING_PROFILES_ACTIVE:local}
# 允许Bean覆盖和循环引用
main:
allow-bean-definition-overriding: true
allow-circular-references: true
# 排除数据库自动配置
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
- org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration
- com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration
# Redis配置
data:
redis:
host: localhost
port: 6379
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD:}
database: 0
timeout: 3000ms
timeout: 10000ms
lettuce:
pool:
max-active: 20
max-idle: 10
min-idle: 5
max-wait: 3000ms
max-active: 8
max-wait: -1ms
max-idle: 8
min-idle: 0
# 网关和Nacos配置
cloud:
nacos:
discovery:
server-addr: localhost:8848
namespace: emotion-dev
group: DEFAULT_GROUP
enabled: false
server-addr: ${NACOS_HOST:localhost}:${NACOS_PORT:8848}
namespace: ${NACOS_NAMESPACE:}
group: ${NACOS_GROUP:DEFAULT_GROUP}
enabled: ${NACOS_DISCOVERY_ENABLED:true}
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
metadata:
version: 1.0.0
zone: ${NACOS_ZONE:default}
config:
enabled: false
server-addr: ${NACOS_HOST:localhost}:${NACOS_PORT:8848}
namespace: ${NACOS_NAMESPACE:}
group: ${NACOS_GROUP:DEFAULT_GROUP}
file-extension: yml
enabled: ${NACOS_CONFIG_ENABLED:false}
username: ${NACOS_USERNAME:nacos}
password: ${NACOS_PASSWORD:nacos}
gateway:
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
# 认证服务路由
- id: emotion-auth
uri: lb://emotion-auth
predicates:
- Path=/api/auth/**
filters:
- StripPrefix=2
# 用户服务路由
- id: emotion-user
uri: lb://emotion-user