Merge pull request #9712 from emqx/fix-bulk-subscribe-failed-in-client.connected-hook

fix: bulk subscribe topics failed in the client.connected hook
This commit is contained in:
Xinyu Liu 2023-01-10 18:22:15 +08:00 committed by GitHub
commit 12de104033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View File

@ -718,15 +718,18 @@ subscribe(#{clientid := ClientID, topic := Topic} = Sub) ->
end.
subscribe_batch(#{clientid := ClientID, topics := Topics}) ->
case lookup(#{clientid => ClientID}) of
{200, _} ->
%% We use emqx_channel instead of emqx_channel_info (used by the emqx_mgmt:lookup_client/2),
%% as the emqx_channel_info table will only be populated after the hook `client.connected`
%% has returned. So if one want to subscribe topics in this hook, it will fail.
case ets:lookup(emqx_channel, ClientID) of
[] ->
{404, ?CLIENT_ID_NOT_FOUND};
_ ->
ArgList = [
[ClientID, Topic, maps:with([qos, nl, rap, rh], Sub)]
|| #{topic := Topic} = Sub <- Topics
],
{200, emqx_mgmt_util:batch_operation(?MODULE, do_subscribe, ArgList)};
{404, ?CLIENT_ID_NOT_FOUND} ->
{404, ?CLIENT_ID_NOT_FOUND}
{200, emqx_mgmt_util:batch_operation(?MODULE, do_subscribe, ArgList)}
end.
unsubscribe(#{clientid := ClientID, topic := Topic}) ->

View File

@ -0,0 +1,2 @@
Fixed the problem of '404 Not Found' when calling the HTTP API '/clients/:clientid/subscribe/bulk'
from the plug-ins and data-bridges on handling the 'client.connected' event.

View File

@ -0,0 +1,2 @@
修复了监听 `client.connected` 事件的插件和数据桥接在调用 `/clients/:clientid/subscribe/bulk`
HTTP 接口时报 `404 Not Found` 的问题。