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) ->
|
list_client_subscriptions(ClientId) ->
|
||||||
Results = [client_subscriptions(Node, ClientId) || Node <- mria_mnesia:running_nodes()],
|
Results = [client_subscriptions(Node, ClientId) || Node <- mria_mnesia:running_nodes()],
|
||||||
Expected = lists:filter(fun({error, _}) -> false;
|
Filter =
|
||||||
([]) -> false;
|
fun
|
||||||
(_) -> true
|
({error, _}) ->
|
||||||
end, Results),
|
false;
|
||||||
case Expected of
|
({_Node, List}) ->
|
||||||
|
erlang:is_list(List) andalso 0 < erlang:length(List)
|
||||||
|
end,
|
||||||
|
case lists:filter(Filter, Results) of
|
||||||
[] -> [];
|
[] -> [];
|
||||||
[Result | _] -> Result
|
[Result | _] -> Result
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -513,11 +513,21 @@ subscribe_batch(post, #{bindings := #{clientid := ClientID}, body := TopicInfos}
|
||||||
subscribe_batch(#{clientid => ClientID, topics => Topics}).
|
subscribe_batch(#{clientid => ClientID, topics => Topics}).
|
||||||
|
|
||||||
subscriptions(get, #{bindings := #{clientid := ClientID}}) ->
|
subscriptions(get, #{bindings := #{clientid := ClientID}}) ->
|
||||||
{Node, Subs0} = emqx_mgmt:list_client_subscriptions(ClientID),
|
case emqx_mgmt:list_client_subscriptions(ClientID) of
|
||||||
Subs = lists:map(fun({Topic, SubOpts}) ->
|
[] ->
|
||||||
#{node => Node, clientid => ClientID, topic => Topic, qos => maps:get(qos, SubOpts)}
|
{200, []};
|
||||||
end, Subs0),
|
{Node, Subs} ->
|
||||||
{200, 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}) ->
|
set_keepalive(put, #{bindings := #{clientid := ClientID}, query_string := Query}) ->
|
||||||
case maps:find(<<"interval">>, Query) of
|
case maps:find(<<"interval">>, Query) of
|
||||||
|
|
Loading…
Reference in New Issue