From 806e444297dad66c82af563ecc88612233a12e96 Mon Sep 17 00:00:00 2001 From: fanfpy Date: Sat, 21 Jun 2025 22:53:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0aktools=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=B9=B6=E6=9B=B4=E6=96=B0=E6=9E=B6=E6=9E=84=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在data-service中添加aktools依赖和运行配置 - 更新Traefik配置添加压缩中间件 - 修改Consul配置启用ACL - 更新README添加架构图和开发指南 - 添加架构图文档 --- README.md | 42 +++++++++++++++++++++- consul/config/consul.hcl | 13 ++++--- docs/architecture.drawio | 49 ++++++++++++++++++++++++++ docs/architecture.svg | 4 +++ services/data-service/Dockerfile | 2 +- services/data-service/app.py | 2 ++ services/data-service/register.py | 9 +++-- services/data-service/requirements.txt | 3 +- traefik/traefik.yml | 9 ++--- 9 files changed, 118 insertions(+), 15 deletions(-) create mode 100644 docs/architecture.drawio create mode 100644 docs/architecture.svg diff --git a/README.md b/README.md index 2564b97..d22d1e7 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,47 @@ ## 使用方式 ```bash -docker-compose up --build +docker compose up --build ``` +## 📦 技术架构 +![架构图](docs/architecture.svg) + +**核心组件**: +- 服务发现:Consul +- API网关:Traefik with Let's Encrypt +- 消息队列:RabbitMQ +- 数据存储:PostgreSQL + Redis + +**通信协议**: +- RESTful API(80% 服务) +- gRPC(quant-service 与 data-service) + +## 🔧 环境变量 +```env +CONSUL_HTTP_ADDR=consul:8500 +ALPHAVANTAGE_API_KEY=your_key +``` + +## 📚 API 文档 +访问统一入口:`http://localhost/docs` + +## 🛠 开发指南 +```bash +# Python 服务 +pip install -r requirements.txt +uvicorn app:app --reload + +# C# 服务 +dotnet run +``` + +## 🤝 贡献规范 +1. 分支命名:feat/xxx, fix/xxx +2. 提交信息遵循 Conventional Commits +3. 提交 PR 前需通过 SonarQube 检测 + +## 📄 许可 +[MIT](LICENSE) + 访问入口:`http://localhost` 或你的服务器域名(如 AriStockAI.com) diff --git a/consul/config/consul.hcl b/consul/config/consul.hcl index d16b9e5..508eec9 100644 --- a/consul/config/consul.hcl +++ b/consul/config/consul.hcl @@ -1,5 +1,8 @@ -datacenter = "dc1" -data_dir = "/consul/data" -server = true -bootstrap_expect = 1 -ui = true \ No newline at end of file +ui_config { + enabled = true +} + +acl { + enabled = true + default_policy = "deny" +} \ No newline at end of file diff --git a/docs/architecture.drawio b/docs/architecture.drawio new file mode 100644 index 0000000..cadf852 --- /dev/null +++ b/docs/architecture.drawio @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/architecture.svg b/docs/architecture.svg new file mode 100644 index 0000000..1632c96 --- /dev/null +++ b/docs/architecture.svg @@ -0,0 +1,4 @@ + + + +
Consul 服务发现
Traefik 网关
微服务集群
基础设施层
微服务集群
📊 数据服务\n(Python)
🧮 量化服务\n(Python)
基础设施层
🖥️ 前端界面\n(Vue.js)
微服务集群
📊 数据服务(Python)
🧮 量化服务(Python)
😀 情绪分析(Python)
⭐ 推荐服务(C#)
👤 用户服务(C#)
\ No newline at end of file diff --git a/services/data-service/Dockerfile b/services/data-service/Dockerfile index da16c83..684ec1c 100644 --- a/services/data-service/Dockerfile +++ b/services/data-service/Dockerfile @@ -4,4 +4,4 @@ WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY . . -CMD ["python", "app.py"] +CMD ["sh", "-c", "aktools run --port 8001 & python register.py && wait"] diff --git a/services/data-service/app.py b/services/data-service/app.py index 18deafa..00a450b 100644 --- a/services/data-service/app.py +++ b/services/data-service/app.py @@ -1,5 +1,6 @@ from flask import Flask, jsonify import threading +import subprocess from register import register_to_consul app = Flask(__name__) @@ -14,4 +15,5 @@ def hello(): if __name__ == "__main__": threading.Thread(target=register_to_consul).start() + subprocess.Popen(["aktools", "run", "--port", "8001"]) app.run(host="0.0.0.0", port=8000) diff --git a/services/data-service/register.py b/services/data-service/register.py index c0083e3..c926e99 100644 --- a/services/data-service/register.py +++ b/services/data-service/register.py @@ -3,8 +3,8 @@ import requests def register_to_consul(): time.sleep(3) # 等待服务稳定再注册 - service_name = "data-service" # 替换为 quant-service/emotion-service 等 - port = 8000 # 替换为 8001, 8002 等 + service_name = "aktools-service" # AKTools 主服务 + port = 8001 # AKTools 端口 payload = { "Name": service_name, @@ -12,7 +12,7 @@ def register_to_consul(): "Address": service_name, # 容器名作为地址 "Port": port, "Check": { - "HTTP": f"http://{service_name}:{port}/health", + "TCP": f"{service_name}:{port}", "Interval": "10s" } } @@ -22,3 +22,6 @@ def register_to_consul(): print(f"[{service_name}] Registered to Consul") except Exception as e: print(f"❌ Consul register failed: {e}") + +if __name__ == "__main__": + register_to_consul() diff --git a/services/data-service/requirements.txt b/services/data-service/requirements.txt index 8ab6294..aa2ae89 100644 --- a/services/data-service/requirements.txt +++ b/services/data-service/requirements.txt @@ -1 +1,2 @@ -flask \ No newline at end of file +flask +aktools \ No newline at end of file diff --git a/traefik/traefik.yml b/traefik/traefik.yml index a6db39b..ebeb765 100644 --- a/traefik/traefik.yml +++ b/traefik/traefik.yml @@ -1,6 +1,7 @@ -api: - dashboard: true - entryPoints: web: - address: ":80" \ No newline at end of file + address: ":80" +http: + middlewares: + compress: + compress: true \ No newline at end of file