Merge pull request #6847 from DDDHuang/fix_clients_sub_api
fix: client subscriptions api
This commit is contained in:
commit
68616f1be4
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue