Discovery 模块¶
核心文件¶
src/by_framework/core/discovery.py- ServiceRegistry, DiscoveryClientsrc/by_framework/util/discovery_http_client.py- DiscoveryHttpClient
core/discovery/ServiceRegistry.javacore/discovery/DiscoveryClient.javautil/http/DiscoveryHttpClient.java
src/discovery/service_registry.tssrc/discovery/discovery_client.tssrc/discovery/discovery_http_client.ts
ServiceRegistry¶
基于 Redis 的服务注册中心。
class ServiceRegistry:
def __init__(self, redis_client: Redis) -> None:
async def register(self, service_name: str, endpoint: str, metadata: Optional[dict] = None) -> None:
async def heartbeat(self, service_name: str, endpoint: str) -> None:
async def unregister(self, service_name: str, endpoint: str) -> None:
DiscoveryClient¶
带缓存的服务发现客户端。
DiscoveryHttpClient¶
结合服务发现的 HTTP 客户端,支持自动重试与故障切换。
class DiscoveryHttpClient:
def __init__(self, redis_client: Redis, service_name: str, max_retries: int = 3) -> None:
async def get(self, path: str, **kwargs) -> httpx.Response:
async def post(self, path: str, **kwargs) -> httpx.Response:
async def download(self, remote_path: str, local_path: str) -> None:
async def upload(self, local_path: str, remote_path: str) -> None:
export class DiscoveryHttpClient {
constructor(params: { discoveryClient: DiscoveryClient; retryConfig?: RetryConfig })
async get(serviceName: string, path: string, params?: RequestParams): Promise<HttpResponse>
async post(serviceName: string, path: string, params?: RequestParams): Promise<HttpResponse>
}