添加核心微服务组件包括数据服务、量化服务、情绪分析服务等 实现基于Consul的服务发现和Traefik网关路由 包含Docker化部署方案和CI/CD Webhook支持
25 lines
743 B
Python
25 lines
743 B
Python
import time
|
|
import requests
|
|
|
|
def register_to_consul():
|
|
time.sleep(3) # 等待服务稳定再注册
|
|
service_name = "quant-service" # 替换为 quant-service/emotion-service 等
|
|
port = 8001 # 替换为 8001, 8002 等
|
|
|
|
payload = {
|
|
"Name": service_name,
|
|
"ID": f"{service_name}-1",
|
|
"Address": service_name, # 容器名作为地址
|
|
"Port": port,
|
|
"Check": {
|
|
"HTTP": f"http://{service_name}:{port}/health",
|
|
"Interval": "10s"
|
|
}
|
|
}
|
|
|
|
try:
|
|
requests.put("http://consul:8500/v1/agent/service/register", json=payload)
|
|
print(f"[{service_name}] Registered to Consul")
|
|
except Exception as e:
|
|
print(f"❌ Consul register failed: {e}")
|