运营商与中继管理

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 / noneearly_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 后,同优先级中继按买价升序排列

配置示例——同一优先级双中继:

优先级中继权重说明
10carrier-a80主用
10carrier-b20备用(20%流量)
20carrier-c100完全备用