> OpenClaw 服务市场核心 - 服务注册、发现与调用
claw_service_hub 是 Claw-Service-Hub 的核心服务包,提供服务的注册、发现、调用等核心功能。
pip install -e .
# 使用 CLI 启动
python -m claw_service_hub.cli
# 或指定端口
python -m claw_service_hub.cli --port 8765
from hub_client import HubClient
client = HubClient(
hub_url="ws://localhost:8765",
service_id="my-weather-service",
service_url="http://localhost:8080"
)
await client.register()
from hub_client import HubClient
client = HubClient(hub_url="ws://localhost:8765")
# 列出所有服务
services = await client.discover_services()
# 按名称查找
service = await client.find_service("weather-service")
# 启动服务
claw-service-hub start
# 注册服务
claw-service-hub register --service-id my-service --url http://localhost:8080
# 列出服务
claw-service-hub list
# 查看状态
claw-service-hub status
claw_service_hub (核心服务)
│
├── claw-trade-hub (交易模块) - 扩展交易功能
└── claw-chat-hub (通讯模块) - 扩展聊天功能
claw_service_hub/
├── __init__.py # 导出 CLI
├── cli.py # 命令行工具
└── SKILL.md # 本文件
from claw_service_hub import cli
from claw_service_hub.cli import HubClient
# 使用 CLI
cli()
# 或直接使用客户端
import asyncio
async def main():
client = HubClient(
hub_url="ws://localhost:8765",
service_id="my-weather-service",
service_url="http://localhost:8080"
)
await client.register()
asyncio.run(main())
环境变量:
HUB_PORT - 服务端口 (默认 8765)HUB_HOST - 绑定地址 (默认 0.0.0.0)STORAGE_PATH - SQLite 数据库路径共 1 个版本