From 55de4ba9572c5094641bc809e19d98ae9797d767 Mon Sep 17 00:00:00 2001 From: edy Date: Mon, 24 Aug 2026 10:48:53 +0800 Subject: [PATCH] =?UTF-8?q?gRPC=20=E7=AB=AF=E5=8F=A3:=20=E6=89=8B=E6=9D=BF?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=2050050=E3=80=81=E9=87=8F=E4=BA=A7=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=2050051?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 避免与常见默认 50051 冲突,并明确两套服务端口。 - 功能手板:GRPC_PORT=50050 - 量产:SOMNI_GRPC_PORT=50051 - 同步 config 默认值、.env.example、compose 映射与单测 Co-authored-by: Cursor --- .env.example | 4 ++-- README.md | 8 ++++---- app/core/config.py | 4 ++-- docker-compose.yml | 4 +++- tests/test_grpc_server.py | 4 ++-- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.env.example b/.env.example index 438fee4..2315edd 100644 --- a/.env.example +++ b/.env.example @@ -5,11 +5,11 @@ APP_DEBUG=false # 功能手板 gRPC(与 HTTP 同进程;明文无鉴权,生产勿对公网裸暴露) GRPC_HOST=0.0.0.0 -GRPC_PORT=50051 +GRPC_PORT=50050 GRPC_ENABLED=true # 量产 gRPC -SOMNI_GRPC_PORT=50052 +SOMNI_GRPC_PORT=50051 SOMNI_GRPC_ENABLED=true # Elasticsearch(功能手板) diff --git a/README.md b/README.md index 92f2723..0fb51c8 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ **Somni / 功能手板音频检索服务**:三维度检索为核心;HTTP 保留;同进程再对外暴露功能手板与量产两套 gRPC。 - **核心**:三维度音频检索(ES 召回 + 标签词典向量 + 精排) -- **功能手板**:`MONGO_*` + `ES_NODE` + `REDIS_URL`;HTTP `:8080` + gRPC `:50051` -- **量产**:`SOMNI_MONGO_*` + `SOMNI_ES_*` + `SOMNI_REDIS_URL`;gRPC `:50052` +- **功能手板**:`MONGO_*` + `ES_NODE` + `REDIS_URL`;HTTP `:8080` + gRPC `:50050` +- **量产**:`SOMNI_MONGO_*` + `SOMNI_ES_*` + `SOMNI_REDIS_URL`;gRPC `:50051` - **写路径**:直连 Mongo,再同步本侧 ES(不再调用 BioNode) - **接口文档**:`docs/功能手板接口文档.md`、`docs/量产接口文档.md` @@ -14,8 +14,8 @@ 算法端 / 调用方 │ ├── HTTP :8080 ──► app/api/audio ──► server/handboard(Fullive) - ├── gRPC :50051 ─► uburnode.v1(手板 audio/quiz) - └── gRPC :50052 ─► uburnode.somni.v1(量产 ListTags/ListAudios/Search/GetAnswer) + ├── gRPC :50050 ─► uburnode.v1(手板 audio/quiz) + └── gRPC :50051 ─► uburnode.somni.v1(量产 ListTags/ListAudios/Search/GetAnswer) ``` ## 目录结构 diff --git a/app/core/config.py b/app/core/config.py index 639d618..46f7cef 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -22,11 +22,11 @@ class Settings(BaseSettings): # 功能手板 gRPC(与 HTTP 同进程;false 时跳过该端口) grpc_host: str = "0.0.0.0" - grpc_port: int = 50051 + grpc_port: int = 50050 grpc_enabled: bool = True # 量产 gRPC - somni_grpc_port: int = 50052 + somni_grpc_port: int = 50051 somni_grpc_enabled: bool = True es_node: str = "http://localhost:9200" diff --git a/docker-compose.yml b/docker-compose.yml index 5bb8e81..03ee717 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,9 @@ services: ES_NODE: http://elasticsearch:9200 REDIS_URL: redis://redis:6379/0 ports: - - "50051:50051" # 对外 gRPC(HTTP 仍经 nginx :8001) + - "50050:50050" # 功能手板 gRPC + - "50051:50051" # 量产 gRPC + # HTTP 仍经 nginx :8001 volumes: - hf_cache:/data/huggingface - ./logs:/app/logs # 宿主机可直接看项目目录 logs/YYYY-MM-DD_ubur_log diff --git a/tests/test_grpc_server.py b/tests/test_grpc_server.py index 9d6c791..ec127e8 100644 --- a/tests/test_grpc_server.py +++ b/tests/test_grpc_server.py @@ -14,10 +14,10 @@ @pytest.mark.asyncio async def test_start_both_servers_when_enabled(monkeypatch: pytest.MonkeyPatch) -> None: fake_hb = MagicMock() - fake_hb.add_insecure_port = MagicMock(return_value=50051) + fake_hb.add_insecure_port = MagicMock(return_value=50050) fake_hb.start = AsyncMock() fake_sm = MagicMock() - fake_sm.add_insecure_port = MagicMock(return_value=50052) + fake_sm.add_insecure_port = MagicMock(return_value=50051) fake_sm.start = AsyncMock() servers = iter([fake_hb, fake_sm]) monkeypatch.setattr(