运营商与中继管理
1. SIP 中继配置
Wholesale 的运营商中继就是 RustPBX 的 SIP 中继(控制台 → SIP Trunk / DID)上附加 wholesale 元数据——健康探活、费率表绑定、租户访问控制都围绕同一个 trunk id。
Wholesale 的中继分为两层:
| 层级 | 配置位置 | 说明 |
|---|---|---|
| SIP 中继 | config/trunks/*.toml 或控制台 | 信令、编解码、最大并发 |
| Wholesale 中继配置 | 数据库 wholesale_trunk_configs | 费率表绑定、熔断器、回铃音 |
1.1 基本 SIP 中继
# config/trunks/carrier_a.toml
[[trunk]]
name = "carrier-a"
dest = "sip:10.0.1.100:5060"
backup_dest = "sip:10.0.1.101:5060" # 备用地址
direction = "outbound"
codec = ["pcmu", "pcma", "g729"]
max_calls = 100
max_cps = 20
weight = 100
# 入向认证
[trunk.auth]
username = "myaccount"
password = "mypassword"
realm = "carrier-a.com"
# 出向注册(如运营商要求)
[trunk.registrar]
enabled = true
username = "myaccount"
password = "mypassword"
expires = 3600
1.2 入向中继(从运营商接收入局呼叫)
[[trunk]]
name = "carrier-a-inbound"
direction = "inbound"
inbound_hosts = ["10.0.1.100", "10.0.1.101"] # 仅允许这些 IP
codec = ["pcmu", "pcma"]
max_calls = 200
1.3 双向中继
[[trunk]]
name = "carrier-b"
dest = "sip:10.0.2.50:5060"
direction = "bidirectional"
inbound_hosts = ["10.0.2.50"]
codec = ["pcmu", "pcma", "g722", "g729"]
max_calls = 500
2. Wholesale 中继配置
在 Web 控制台 Wholesale → 中继管理 中为每个中继设置:
| 配置项 | 说明 | 默认值 |
|---|---|---|
| 买费率表 | 该中继的成本费率 | 无 |
| 熔断器启用 | 是否启用三态熔断 | false |
| 回铃音模式 | early_media / local_ring / none | early_media |
| 号码改写 | 发送到该中继前的号码变换 | 无 |
| 技术前缀 | 拨号前自动添加的前缀 | 无 |
2.1 号码改写规则
每个中继可以配置出向号码改写:
{
"caller_strip": 0,
"caller_prepend": "",
"callee_strip": 0,
"callee_prepend": "0",
"callee_regex": ""
}
改写管道:原始号码 → strip → prepend → regex
3. 中继健康检查
3.1 OPTIONS 探测
RustPBX 核心支持对中继目标发送 SIP OPTIONS 进行可达性检测:
[[trunk]]
name = "carrier-a"
dest = "sip:10.0.1.100:5060"
[trunk.health_check]
enabled = true
interval_secs = 30
timeout_secs = 5
max_failures = 3
3.2 Wholesale 熔断器
Wholesale 模块提供更强大的 三态熔断器:
Closed ──(连续 N 次失败)──► Open ──(等待冷却)──► HalfOpen ──(探测成功)──► Closed
▲ │
└──────(探测失败)────────────────┘
| 参数 | 说明 | 默认值 |
|---|---|---|
| failure_threshold | 连续失败次数触发熔断 | 5 |
| open_duration_secs | 熔断持续时间 | 30 |
| half_open_probes | 半开状态探测次数 | 1 |
| failure_codes | 视为失败的 SIP 状态码 | [503, 408, 504] |
在控制台 Wholesale → 监控限流 中可查看所有中继的熔断状态,手动重置或启用/禁用。
4. 多中继负载均衡
当路由策略中同一优先级有多个中继时:
| 算法 | 说明 |
|---|---|
| 加权轮询 | 按 weight 字段分配(默认) |
| LCR | 启用租户 lcr_enabled 后,同优先级中继按买价升序排列 |
配置示例——同一优先级双中继:
| 优先级 | 中继 | 权重 | 说明 |
|---|---|---|---|
| 10 | carrier-a | 80 | 主用 |
| 10 | carrier-b | 20 | 备用(20%流量) |
| 20 | carrier-c | 100 | 完全备用 |