|
@@ -88,22 +88,6 @@ fields(config) ->
|
|
|
desc => ?DESC("connect_timeout")
|
|
desc => ?DESC("connect_timeout")
|
|
|
}
|
|
}
|
|
|
)},
|
|
)},
|
|
|
- {max_retries,
|
|
|
|
|
- sc(
|
|
|
|
|
- non_neg_integer(),
|
|
|
|
|
- #{
|
|
|
|
|
- default => 5,
|
|
|
|
|
- desc => ?DESC("max_retries")
|
|
|
|
|
- }
|
|
|
|
|
- )},
|
|
|
|
|
- {retry_interval,
|
|
|
|
|
- sc(
|
|
|
|
|
- emqx_schema:duration(),
|
|
|
|
|
- #{
|
|
|
|
|
- default => "1s",
|
|
|
|
|
- desc => ?DESC("retry_interval")
|
|
|
|
|
- }
|
|
|
|
|
- )},
|
|
|
|
|
{pool_type,
|
|
{pool_type,
|
|
|
sc(
|
|
sc(
|
|
|
pool_type(),
|
|
pool_type(),
|
|
@@ -147,6 +131,14 @@ fields("request") ->
|
|
|
{path, hoconsc:mk(binary(), #{required => false, desc => ?DESC("path")})},
|
|
{path, hoconsc:mk(binary(), #{required => false, desc => ?DESC("path")})},
|
|
|
{body, hoconsc:mk(binary(), #{required => false, desc => ?DESC("body")})},
|
|
{body, hoconsc:mk(binary(), #{required => false, desc => ?DESC("body")})},
|
|
|
{headers, hoconsc:mk(map(), #{required => false, desc => ?DESC("headers")})},
|
|
{headers, hoconsc:mk(map(), #{required => false, desc => ?DESC("headers")})},
|
|
|
|
|
+ {max_retries,
|
|
|
|
|
+ sc(
|
|
|
|
|
+ non_neg_integer(),
|
|
|
|
|
+ #{
|
|
|
|
|
+ required => false,
|
|
|
|
|
+ desc => ?DESC("max_retries")
|
|
|
|
|
+ }
|
|
|
|
|
+ )},
|
|
|
{request_timeout,
|
|
{request_timeout,
|
|
|
sc(
|
|
sc(
|
|
|
emqx_schema:duration_ms(),
|
|
emqx_schema:duration_ms(),
|
|
@@ -182,8 +174,6 @@ on_start(
|
|
|
path := BasePath
|
|
path := BasePath
|
|
|
},
|
|
},
|
|
|
connect_timeout := ConnectTimeout,
|
|
connect_timeout := ConnectTimeout,
|
|
|
- max_retries := MaxRetries,
|
|
|
|
|
- retry_interval := RetryInterval,
|
|
|
|
|
pool_type := PoolType,
|
|
pool_type := PoolType,
|
|
|
pool_size := PoolSize
|
|
pool_size := PoolSize
|
|
|
} = Config
|
|
} = Config
|
|
@@ -206,8 +196,6 @@ on_start(
|
|
|
{host, Host},
|
|
{host, Host},
|
|
|
{port, Port},
|
|
{port, Port},
|
|
|
{connect_timeout, ConnectTimeout},
|
|
{connect_timeout, ConnectTimeout},
|
|
|
- {retry, MaxRetries},
|
|
|
|
|
- {retry_timeout, RetryInterval},
|
|
|
|
|
{keepalive, 30000},
|
|
{keepalive, 30000},
|
|
|
{pool_type, PoolType},
|
|
{pool_type, PoolType},
|
|
|
{pool_size, PoolSize},
|
|
{pool_size, PoolSize},
|
|
@@ -247,17 +235,23 @@ on_query(InstId, {send_message, Msg}, AfterQuery, State) ->
|
|
|
path := Path,
|
|
path := Path,
|
|
|
body := Body,
|
|
body := Body,
|
|
|
headers := Headers,
|
|
headers := Headers,
|
|
|
- request_timeout := Timeout
|
|
|
|
|
|
|
+ request_timeout := Timeout,
|
|
|
|
|
+ max_retries := Retry
|
|
|
} = process_request(Request, Msg),
|
|
} = process_request(Request, Msg),
|
|
|
- on_query(InstId, {Method, {Path, Headers, Body}, Timeout}, AfterQuery, State)
|
|
|
|
|
|
|
+ on_query(
|
|
|
|
|
+ InstId,
|
|
|
|
|
+ {undefined, Method, {Path, Headers, Body}, Timeout, Retry},
|
|
|
|
|
+ AfterQuery,
|
|
|
|
|
+ State
|
|
|
|
|
+ )
|
|
|
end;
|
|
end;
|
|
|
on_query(InstId, {Method, Request}, AfterQuery, State) ->
|
|
on_query(InstId, {Method, Request}, AfterQuery, State) ->
|
|
|
- on_query(InstId, {undefined, Method, Request, 5000}, AfterQuery, State);
|
|
|
|
|
|
|
+ on_query(InstId, {undefined, Method, Request, 5000, 2}, AfterQuery, State);
|
|
|
on_query(InstId, {Method, Request, Timeout}, AfterQuery, State) ->
|
|
on_query(InstId, {Method, Request, Timeout}, AfterQuery, State) ->
|
|
|
- on_query(InstId, {undefined, Method, Request, Timeout}, AfterQuery, State);
|
|
|
|
|
|
|
+ on_query(InstId, {undefined, Method, Request, Timeout, 2}, AfterQuery, State);
|
|
|
on_query(
|
|
on_query(
|
|
|
InstId,
|
|
InstId,
|
|
|
- {KeyOrNum, Method, Request, Timeout},
|
|
|
|
|
|
|
+ {KeyOrNum, Method, Request, Timeout, Retry},
|
|
|
AfterQuery,
|
|
AfterQuery,
|
|
|
#{pool_name := PoolName, base_path := BasePath} = State
|
|
#{pool_name := PoolName, base_path := BasePath} = State
|
|
|
) ->
|
|
) ->
|
|
@@ -275,7 +269,8 @@ on_query(
|
|
|
end,
|
|
end,
|
|
|
Method,
|
|
Method,
|
|
|
NRequest,
|
|
NRequest,
|
|
|
- Timeout
|
|
|
|
|
|
|
+ Timeout,
|
|
|
|
|
+ Retry
|
|
|
)
|
|
)
|
|
|
of
|
|
of
|
|
|
{error, Reason} ->
|
|
{error, Reason} ->
|
|
@@ -368,7 +363,8 @@ preprocess_request(
|
|
|
path => emqx_plugin_libs_rule:preproc_tmpl(Path),
|
|
path => emqx_plugin_libs_rule:preproc_tmpl(Path),
|
|
|
body => emqx_plugin_libs_rule:preproc_tmpl(Body),
|
|
body => emqx_plugin_libs_rule:preproc_tmpl(Body),
|
|
|
headers => preproc_headers(Headers),
|
|
headers => preproc_headers(Headers),
|
|
|
- request_timeout => maps:get(request_timeout, Req, 30000)
|
|
|
|
|
|
|
+ request_timeout => maps:get(request_timeout, Req, 30000),
|
|
|
|
|
+ max_retries => maps:get(max_retries, Req, 2)
|
|
|
}.
|
|
}.
|
|
|
|
|
|
|
|
preproc_headers(Headers) when is_map(Headers) ->
|
|
preproc_headers(Headers) when is_map(Headers) ->
|