Merge pull request #7308 from zhongwencool/set-keepalive-via-body

feat: Support set keepalive via queryString & Body HTTP API.
This commit is contained in:
zhongwencool 2022-03-15 14:30:42 +08:00 committed by GitHub
commit dd86ece33e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 4 deletions

View File

@ -22,8 +22,8 @@ File format:
* CLI `emqx_ctl pem_cache clean` to force purge x509 certificate cache, * CLI `emqx_ctl pem_cache clean` to force purge x509 certificate cache,
to force an immediate reload of all certificates after the files are updated on disk. to force an immediate reload of all certificates after the files are updated on disk.
* Refactor the ExProto so that anonymous clients can also be displayed on the dashboard [#6983] * Refactor the ExProto so that anonymous clients can also be displayed on the dashboard [#6983]
* Force shutdown of processe that cannot answer takeover event [#7026] * Force shutdown of processes that cannot answer takeover event [#7026]
* Support set keepalive via queryString & Body HTTP API.
* `topic` parameter in bridge configuration can have `${node}` substitution (just like in `clientid` parameter) * `topic` parameter in bridge configuration can have `${node}` substitution (just like in `clientid` parameter)
### Bug fixes ### Bug fixes

View File

@ -257,7 +257,7 @@ set_keepalive(#{clientid := ClientId}, Params) ->
undefined -> undefined ->
minirest:return({error, ?ERROR7, params_not_found}); minirest:return({error, ?ERROR7, params_not_found});
Interval0 -> Interval0 ->
Interval = binary_to_integer(Interval0), Interval = to_integer(Interval0),
case emqx_mgmt:set_keepalive(emqx_mgmt_util:urldecode(ClientId), Interval) of case emqx_mgmt:set_keepalive(emqx_mgmt_util:urldecode(ClientId), Interval) of
ok -> minirest:return(); ok -> minirest:return();
{error, not_found} -> minirest:return({error, ?ERROR12, not_found}); {error, not_found} -> minirest:return({error, ?ERROR12, not_found});
@ -266,6 +266,9 @@ set_keepalive(#{clientid := ClientId}, Params) ->
end end
end. end.
to_integer(Int)when is_integer(Int) -> Int;
to_integer(Bin) when is_binary(Bin) -> binary_to_integer(Bin).
%% @private %% @private
%% S = 100,1s %% S = 100,1s
%% | 100KB, 1m %% | 100KB, 1m

View File

@ -977,7 +977,9 @@ handle_call({quota, Policy}, Channel) ->
reply(ok, Channel#channel{quota = Quota}); reply(ok, Channel#channel{quota = Quota});
handle_call({keepalive, Interval}, Channel = #channel{keepalive = KeepAlive, handle_call({keepalive, Interval}, Channel = #channel{keepalive = KeepAlive,
conninfo = ConnInfo}) -> conninfo = ConnInfo, timers = Timers}) ->
AliveTimer = maps:get(alive_timer, Timers, undefined),
emqx_misc:cancel_timer(AliveTimer),
ClientId = info(clientid, Channel), ClientId = info(clientid, Channel),
NKeepalive = emqx_keepalive:set(interval, Interval * 1000, KeepAlive), NKeepalive = emqx_keepalive:set(interval, Interval * 1000, KeepAlive),
NConnInfo = maps:put(keepalive, Interval, ConnInfo), NConnInfo = maps:put(keepalive, Interval, ConnInfo),