fix(mgmt): sub/unsub a share subscription to the client via http api

- `/clients/:clientid/subscribe`
- `/clients/:clientid/subscribe/bulk`
- `/clients/:clientid/unsubscribe`
- `/clients/:clientid/unsubscribe/bulk`
This commit is contained in:
JimMoen 2024-02-27 14:15:27 +08:00
parent a3e81c5039
commit a76415c4f6
No known key found for this signature in database
3 changed files with 10 additions and 6 deletions

View File

@ -269,10 +269,11 @@ do_join(_TopicAcc, [C | Words]) when ?MULTI_LEVEL_WILDCARD_NOT_LAST(C, Words) ->
do_join(TopicAcc, [Word | Words]) ->
do_join(<<TopicAcc/binary, "/", (bin(Word))/binary>>, Words).
-spec parse(topic() | {topic(), map()}) -> {topic() | share(), map()}.
parse(TopicFilter) when is_binary(TopicFilter) ->
-spec parse(TF | {TF, map()}) -> {TF, map()} when
TF :: topic() | share().
parse(TopicFilter) when ?IS_TOPIC(TopicFilter) ->
parse(TopicFilter, #{});
parse({TopicFilter, Options}) when is_binary(TopicFilter) ->
parse({TopicFilter, Options}) when ?IS_TOPIC(TopicFilter) ->
parse(TopicFilter, Options).
-spec parse(topic() | share(), map()) -> {topic() | share(), map()}.

View File

@ -2,7 +2,7 @@
{application, emqx_management, [
{description, "EMQX Management API and CLI"},
% strict semver, bump manually!
{vsn, "5.0.37"},
{vsn, "5.0.38"},
{modules, []},
{registered, [emqx_management_sup]},
{applications, [

View File

@ -781,10 +781,13 @@ subscribe_batch(#{clientid := ClientID, topics := Topics}) ->
end.
unsubscribe(#{clientid := ClientID, topic := Topic}) ->
{NTopic, _} = emqx_topic:parse(Topic),
case do_unsubscribe(ClientID, Topic) of
{error, channel_not_found} ->
{404, ?CLIENTID_NOT_FOUND};
{unsubscribe, [{Topic, #{}}]} ->
{unsubscribe, [{UnSubedT, #{}}]} when
(UnSubedT =:= NTopic) orelse (UnSubedT =:= Topic)
->
{204}
end.
@ -809,7 +812,7 @@ do_subscribe(ClientID, Topic0, Options) ->
{subscribe, Subscriptions, Node} ->
case proplists:is_defined(Topic, Subscriptions) of
true ->
{ok, Options#{node => Node, clientid => ClientID, topic => Topic}};
{ok, Options#{node => Node, clientid => ClientID, topic => Topic0}};
false ->
{error, unknow_error}
end