dispatcher 模組:從檔案或資料庫讀取轉送目的,規則可以是 round-robin、weight based load balancing、call load distribution、hashing over SIP 封包內容等。
- 可作為 stateless load balancer。如果需要自動偵測 gateways 是否正常運作,則需要 tm 模組。
- lightweight 所以執行速度快
- 可以 runtime 重新載入 routing records
參數
- 檔案:list_file
- 資料庫:db_url, table_name, setid_col, destination_col, flags_col, priority_col
- force_dst, flags (影響 dispatcher 行為), use_default, dst_avp, grp_avp,
cnt_avp, dstid_avp, attrs_avp, hash_pvar, setid_pvname, attrs_pvname
- probe:ds_ping_method, ds_ping_from, ds_ping_interval
- ds_probing_threshold, ds_ping_reply_codes, ds_probing_mode,
ds_hash_size, ds_hash_expire, ds_hash_initexpire,
ds_hash_check_interval, outbound_proxy
函數
- ds_select_dst(setid, alg [, limit]):設定 dst_uri 欄位 (也就是 outbound proxy address 或 $du 變數),請求 URI 沒動。
- setid:destination set ID
- alg:選擇 destination 使用的演算法
- limit
- ds_select_domain(setid, alg [, limit]):改寫請求 URI
- ds_next_dst(), ds_next_domain()
- ds_mark_dst()
- ds_is_from_list(
- ds_load_update()
- ds_load_unset()
MI 或 RPC 指令
- ds_set_state
- ds_list
- ds_reload
應用範例
stateless forwarding
# Dispatch requests
route[DISPATCH] {
# round robin dispatching on gateways group '1'
if(!ds_select_dst("1", "4"))
{
send_reply("404", "No destination");
exit;
}
xlog("L_DBG", "--- SCRIPT: going to <$ru> via <$du>\n");
forward("RTF_DISPATCH");
exit;
}
stateful forwarding
# Dispatch requests
route[DISPATCH] {
# round robin dispatching on gateways group '1'
if(!ds_select_dst("1", "4"))
{
send_reply("404", "No destination");
exit;
}
xlog("L_DBG", "--- SCRIPT: going to <$ru> via <$du>\n");
t_on_failure("RTF_DISPATCH");
t_relay();
exit;
}
# Sample failure route
failure_route[RTF_DISPATCH] {
if (t_is_canceled()) {
exit;
}
# next DST - only for 500 or local timeout
if (t_check_status("500")
or (t_branch_timeout() and !t_branch_replied()))
{
if(ds_next_dst())
{
t_on_failure("RTF_DISPATCH");
t_relay();
exit;
}
}
}
discard
route {
);
}
to one host
route {
forward(1.2.3.4);
}
或
route {
rewritehost(1.2.3.4);
forward();
}
參考來源
- dispatcher
- 簡報:Kamailio - Load Balancing Load Balancers
延伸閱讀
沒有留言:
張貼留言