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,89 +1,82 @@
server:
port: 19002
# 本地开发环境配置
spring:
application:
name: emotion-ai
cloud:
nacos:
discovery:
server-addr: localhost:8848
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
config:
server-addr: localhost:8848
namespace:
group: DEFAULT_GROUP
file-extension: yml
enabled: false
username: nacos
password: Peanut2817*#
# 数据源配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/emotion_museum?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: root
password: 123456
# Redis配置
data:
redis:
host: localhost
port: 6379
password:
database: 1
timeout: 10000ms
lettuce:
pool:
max-active: 8
max-wait: -1ms
max-idle: 8
min-idle: 0
password:
database: 0
# MyBatis Plus配置
mybatis-plus:
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
logic-delete-field: isDeleted
logic-delete-value: 1
logic-not-delete-value: 0
# Nacos配置
spring:
cloud:
nacos:
discovery:
server-addr: localhost:8848
namespace:
group: DEFAULT_GROUP
enabled: true
register-enabled: true
heart-beat-interval: 5000
heart-beat-timeout: 15000
ip-delete-timeout: 30000
config:
server-addr: localhost:8848
namespace:
group: DEFAULT_GROUP
file-extension: yml
enabled: false
# Coze API配置
# Coze平台配置
coze:
api:
base-url: https://api.coze.cn
token: ${COZE_API_TOKEN:your_coze_api_token}
bot-id: 7523042446285439016
workflow-id: 7523047462895796287
timeout: 30000
base-url: https://api.coze.cn
api-key: your-coze-api-key
bot-id: 7523042446285439016
workflow-id: 7523047462895796287
user-id: emotion-museum-user
token: pat_GCR4qKzqpf90wMCvKsldMrB18KG3QsLDci65bZthssKsbLxu8X70BKYumleDcabO
timeout: 60
max-retries: 3
stream: false
model:
temperature: 0.7
max-tokens: 1000
top-p: 0.9
frequency-penalty: 0.0
presence-penalty: 0.0
# 功能开关配置
features:
emotion-analysis:
enabled: false
auto-analyze: false
chat:
enabled: true
stream: false
# 日志配置
logging:
level:
com.emotionmuseum: 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"
com.baomidou.mybatisplus: debug
com.alibaba.nacos: info
file:
name: logs/emotion-ai-local.log
# 管理端点配置
management:
endpoints:
web:
exposure:
include: health,info,metrics
endpoint:
health:
show-details: always
@@ -0,0 +1,82 @@
# 本地开发环境配置
spring:
cloud:
nacos:
discovery:
server-addr: localhost:8848
namespace:
group: DEFAULT_GROUP
enabled: true
username: nacos
password: nacos
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
config:
server-addr: localhost:8848
namespace:
group: DEFAULT_GROUP
file-extension: yml
enabled: false
username: nacos
password: nacos
# 数据源配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/emotion_museum?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: root
password: 123456
# Redis配置
data:
redis:
host: localhost
port: 6379
password:
database: 0
# Coze平台配置
coze:
base-url: https://api.coze.cn
api-key: your-coze-api-key
bot-id: 7523042446285439016
workflow-id: 7523047462895796287
user-id: emotion-museum-user
token: pat_GCR4qKzqpf90wMCvKsldMrB18KG3QsLDci65bZthssKsbLxu8X70BKYumleDcabO
timeout: 60
max-retries: 3
stream: false
model:
temperature: 0.7
max-tokens: 1000
top-p: 0.9
frequency-penalty: 0.0
presence-penalty: 0.0
# 功能开关配置
features:
emotion-analysis:
enabled: false
auto-analyze: false
chat:
enabled: true
stream: false
# 日志配置
logging:
level:
com.emotionmuseum: debug
com.baomidou.mybatisplus: debug
com.alibaba.nacos: info
file:
name: logs/emotion-ai-local.log
@@ -1,95 +1,55 @@
server:
port: 9002
# 生产环境配置
spring:
application:
name: emotion-ai
main:
allow-bean-definition-overriding: true
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
# 数据源配置
datasource:
url: jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:emotion_museum}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: ${MYSQL_USERNAME:root}
password: ${MYSQL_PASSWORD:123456}
driver-class-name: com.mysql.cj.jdbc.Driver
hikari:
pool-name: EmotionAiHikariCP
minimum-idle: 5
maximum-pool-size: 20
auto-commit: true
idle-timeout: 30000
max-lifetime: 1800000
connection-timeout: 30000
url: jdbc:mysql://47.111.10.27:3306/emotion_museum?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: root
password: EmotionMuseum2025*#
# Redis配置
data:
redis:
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}
host: 47.111.10.27
port: 6379
password: EmotionMuseum2025*#
database: 0
timeout: 3000ms
lettuce:
pool:
max-active: 20
max-idle: 10
min-idle: 5
max-wait: 3000ms
# MyBatis Plus配置
mybatis-plus:
configuration:
map-underscore-to-camel-case: true
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
global-config:
db-config:
id-type: input
logic-delete-field: is_deleted
logic-delete-value: 1
logic-not-delete-value: 0
mapper-locations: classpath*:mapper/*.xml
# Coze平台配置
coze:
base-url: ${COZE_BASE_URL:https://api.coze.cn}
api-key: ${COZE_API_KEY:your-coze-api-key}
bot-id: ${COZE_BOT_ID:7523042446285439016}
workflow-id: ${COZE_WORKFLOW_ID:7523047462895796287}
user-id: ${COZE_USER_ID:emotion-museum-user}
token: pat_GCR4qKzqpf90wMCvKsldMrB18KG3QsLDci65bZthssKsbLxu8X70BKYumleDcabO
timeout: 60
max-retries: 3
stream: false
model:
temperature: 0.7
max-tokens: 1000
top-p: 0.9
frequency-penalty: 0.0
presence-penalty: 0.0
# 日志配置
logging:
level:
com.emotionmuseum: INFO
com.baomidou.mybatisplus: DEBUG
pattern:
console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n"
# 管理端点
management:
endpoints:
web:
exposure:
include: health,info,metrics
endpoint:
health:
show-details: always
com.emotionmuseum: warn
com.baomidou.mybatisplus: warn
com.alibaba.nacos: error
file:
name: logs/emotion-ai-prod.log
@@ -0,0 +1,55 @@
# 测试环境配置
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
# 数据源配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://47.111.10.27:3306/emotion_museum?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: root
password: EmotionMuseum2025*#
# Redis配置
data:
redis:
host: 47.111.10.27
port: 6379
password: EmotionMuseum2025*#
database: 0
# 日志配置
logging:
level:
com.emotionmuseum: info
com.baomidou.mybatisplus: info
com.alibaba.nacos: warn
file:
name: logs/emotion-ai-test.log
@@ -4,44 +4,58 @@ server:
spring:
application:
name: emotion-ai
# 配置文件激活
profiles:
active: dev
data:
redis:
host: localhost
port: 6379
database: 0
timeout: 3000ms
lettuce:
pool:
max-active: 20
max-idle: 10
min-idle: 5
max-wait: 3000ms
# 本地数据库配置(备用)
active: ${SPRING_PROFILES_ACTIVE:local}
# 允许Bean覆盖和循环引用
main:
allow-bean-definition-overriding: true
allow-circular-references: true
# 数据源配置
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/emotion_museum?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: ${DB_USERNAME:root}
password: ${DB_PASSWORD:123456}
url: jdbc:mysql://${MYSQL_HOST:localhost}:${MYSQL_PORT:3306}/${MYSQL_DATABASE:emotion_museum}?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: ${MYSQL_USERNAME:root}
password: ${MYSQL_PASSWORD:123456}
hikari:
minimum-idle: 5
maximum-pool-size: 20
auto-commit: true
idle-timeout: 30000
pool-name: EmotionAiHikariCP
max-lifetime: 1800000
connection-timeout: 30000
connection-test-query: SELECT 1
# Redis配置
data:
redis:
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}
password: ${REDIS_PASSWORD:}
database: 1
timeout: 10000ms
lettuce:
pool:
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:false}
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}