From 01350c810e1184e37383a8e5087b701bd789371e Mon Sep 17 00:00:00 2001 From: Leon <8544842+leon14631@user.noreply.gitee.com> Date: Wed, 15 Jun 2022 07:14:36 +0000 Subject: [PATCH 1/2] =?UTF-8?q?update=20server/WebHook.cpp.=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6HOOK=E6=B7=BB=E5=8A=A0retry=20?= =?UTF-8?q?=EF=BC=8C=E8=AE=BE=E7=BD=AEhook=E9=80=9A=E7=9F=A5=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=87=8D=E8=AF=95=E7=9A=84=E6=AC=A1=E6=95=B0=E3=80=82?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=BA0=EF=BC=8C=E4=B8=8D=E9=87=8D?= =?UTF-8?q?=E8=AF=95=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/WebHook.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/server/WebHook.cpp b/server/WebHook.cpp index d0470af0..5a5a2926 100755 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved. * * This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit). @@ -47,6 +47,7 @@ const string kOnServerStarted = HOOK_FIELD"on_server_started"; const string kOnServerKeepalive = HOOK_FIELD"on_server_keepalive"; const string kAdminParams = HOOK_FIELD"admin_params"; const string kAliveInterval = HOOK_FIELD"alive_interval"; +const string kRetry = HOOK_FIELD"retry"; onceToken token([](){ mINI::Instance()[kEnable] = false; @@ -68,6 +69,8 @@ onceToken token([](){ mINI::Instance()[kOnServerKeepalive] = ""; mINI::Instance()[kAdminParams] = "secret=035c73f7-bb6b-4889-a715-d9eb2d1925cc"; mINI::Instance()[kAliveInterval] = 30.0; + mINI::Instance()[kRetry] = 0; + },nullptr); }//namespace Hook @@ -85,6 +88,8 @@ static onceToken token([]() { }//namespace Cluster +void do_http_process(HttpRequester::Ptr &requester,const string &url, const string& bodyStr, const function &func,int retry,float timeout_sec); + static void parse_http_response(const SockException &ex, const Parser &res, const function &fun){ if (ex) { @@ -150,6 +155,7 @@ string getVhost(const HttpArgs &value) { void do_http_hook(const string &url,const ArgsType &body,const function &func){ GET_CONFIG(string, mediaServerId, General::kMediaServerId); GET_CONFIG(float, hook_timeoutSec, Hook::kTimeoutSec); + GET_CONFIG(int, hook_retry, Hook::kRetry); const_cast(body)["mediaServerId"] = mediaServerId; HttpRequester::Ptr requester(new HttpRequester); @@ -161,8 +167,14 @@ void do_http_hook(const string &url,const ArgsType &body,const functionaddHeader("X-VHOST", vhost); } + + do_http_process(requester,url,bodyStr,func,hook_retry,hook_timeoutSec); +} + +void do_http_process(HttpRequester::Ptr &requester,const string &url, const string& bodyStr, const function &func,int retry,float timeout_sec){ + std::shared_ptr pTicker(new Ticker); - requester->startRequester(url, [url, func, bodyStr, requester, pTicker](const SockException &ex, + requester->startRequester(url, [url, func, bodyStr, requester, pTicker,retry,timeout_sec](const SockException &ex, const Parser &res) mutable{ onceToken token(nullptr, [&]() mutable{ requester.reset(); @@ -176,8 +188,14 @@ void do_http_hook(const string &url,const ArgsType &body,const functionelapsedTime() > 500) { DebugL << "hook " << url << " " << pTicker->elapsedTime() << "ms,success:" << bodyStr; } + //尾部递归重试 + if (!err.empty() && retry-- > 0) { + //WarnL << "----------------hook retry------------------ " << retry ; + HttpRequester::Ptr requester(new HttpRequester); + do_http_process(requester,url,bodyStr,func,retry,timeout_sec); + } }); - }, hook_timeoutSec); + }, timeout_sec); } static ArgsType make_json(const MediaInfo &args){ From 6d701bfef5b8727df5d98b9e1b1c30a0fe4edb38 Mon Sep 17 00:00:00 2001 From: Leon <8544842+leon14631@user.noreply.gitee.com> Date: Wed, 15 Jun 2022 07:17:02 +0000 Subject: [PATCH 2/2] =?UTF-8?q?update=20conf/config.ini.=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6HOOK=E6=B7=BB=E5=8A=A0retry=20?= =?UTF-8?q?=EF=BC=8C=E8=AE=BE=E7=BD=AEhook=E9=80=9A=E7=9F=A5=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E9=87=8D=E8=AF=95=E7=9A=84=E6=AC=A1=E6=95=B0=E3=80=82?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E4=B8=BA0=EF=BC=8C=E4=B8=8D=E9=87=8D?= =?UTF-8?q?=E8=AF=95=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/config.ini | 2 ++ 1 file changed, 2 insertions(+) diff --git a/conf/config.ini b/conf/config.ini index 13729497..5097bb0a 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -157,6 +157,8 @@ on_server_keepalive=https://127.0.0.1/index/hook/on_server_keepalive timeoutSec=10 #keepalive hook触发间隔,单位秒,float类型 alive_interval=10.0 +#hook通知重试次数 +retry=2 [cluster] #设置源站拉流url模板, 格式跟printf类似,第一个%s指定app,第二个%s指定stream_id,