Merge pull request #6847 from DDDHuang/fix_clients_sub_api

fix: client subscriptions api
This commit is contained in:
Shawn 2022-01-25 13:30:54 +08:00 committed by GitHub
commit 68616f1be4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 10 deletions

View File

@ -269,11 +269,14 @@ list_authz_cache(ClientId) ->
list_client_subscriptions(ClientId) ->
Results = [client_subscriptions(Node, ClientId) || Node <- mria_mnesia:running_nodes()],
Expected = lists:filter(fun({error, _}) -> false;
([]) -> false;
(_) -> true
end, Results),
case Expected of
Filter =
fun
({error, _}) ->
false;
({_Node, List}) ->
erlang:is_list(List) andalso 0 < erlang:length(List)
end,
case lists:filter(Filter, Results) of
[] -> [];
[Result | _] -> Result
end.

View File

@ -513,11 +513,21 @@ subscribe_batch(post, #{bindings := #{clientid := ClientID}, body := TopicInfos}
subscribe_batch(#{clientid => ClientID, topics => Topics}).
subscriptions(get, #{bindings := #{clientid := ClientID}}) ->
{Node, Subs0} = emqx_mgmt:list_client_subscriptions(ClientID),
Subs = lists:map(fun({Topic, SubOpts}) ->
#{node => Node, clientid => ClientID, topic => Topic, qos => maps:get(qos, SubOpts)}
end, Subs0),
{200, Subs}.
case emqx_mgmt:list_client_subscriptions(ClientID) of
[] ->
{200, []};
{Node, Subs} ->
Formatter =
fun({Topic, SubOpts}) ->
#{
node => Node,
clientid => ClientID,
topic => Topic,
qos => maps:get(qos, SubOpts)
}
end,
{200, lists:map(Formatter, Subs)}
end.
set_keepalive(put, #{bindings := #{clientid := ClientID}, query_string := Query}) ->
case maps:find(<<"interval">>, Query) of