fix(auto_subscribe): update config in cluster
This commit is contained in:
parent
888e7fd727
commit
f19ccdfcde
|
@ -16,6 +16,8 @@
|
|||
|
||||
-module(emqx_auto_subscribe).
|
||||
|
||||
-include_lib("emqx/include/logger.hrl").
|
||||
|
||||
-define(HOOK_POINT, 'client.connected').
|
||||
|
||||
-define(MAX_AUTO_SUBSCRIBE, 20).
|
||||
|
@ -80,8 +82,18 @@ format(Rule = #{topic := Topic}) when is_map(Rule) ->
|
|||
}.
|
||||
|
||||
update_(Topics) when length(Topics) =< ?MAX_AUTO_SUBSCRIBE ->
|
||||
{ok, _} = emqx:update_config([auto_subscribe, topics], Topics),
|
||||
update_hook();
|
||||
case emqx_conf:update([auto_subscribe, topics],
|
||||
Topics,
|
||||
#{rawconf_with_defaults => true, override_to => cluster}) of
|
||||
{ok, #{config := NewTopics}} ->
|
||||
ok = update_hook(),
|
||||
{ok, NewTopics};
|
||||
{error, Reason} ->
|
||||
?LOG(error, "Auto Subscribe update config failed: ~0p", [Reason]),
|
||||
{error, Reason}
|
||||
end;
|
||||
% {ok, _} = emqx:update_config([auto_subscribe, topics], Topics),
|
||||
% update_hook();
|
||||
update_(_Topics) ->
|
||||
{error, quota_exceeded}.
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
-export([auto_subscribe/2]).
|
||||
|
||||
-define(INTERNAL_ERROR, 'INTERNAL_ERROR').
|
||||
-define(EXCEED_LIMIT, 'EXCEED_LIMIT').
|
||||
-define(BAD_REQUEST, 'BAD_REQUEST').
|
||||
|
||||
|
@ -90,6 +91,9 @@ auto_subscribe(put, #{body := Params}) ->
|
|||
Message = list_to_binary(io_lib:format("Max auto subscribe topic count is ~p",
|
||||
[emqx_auto_subscribe:max_limit()])),
|
||||
{409, #{code => ?EXCEED_LIMIT, message => Message}};
|
||||
ok ->
|
||||
{200, emqx_auto_subscribe:list()}
|
||||
{error, Reason} ->
|
||||
Message = list_to_binary(io_lib:format("Update config failed ~p", [Reason])),
|
||||
{500, #{code => ?INTERNAL_ERROR, message => Message}};
|
||||
{ok, NewTopics} ->
|
||||
{200, NewTopics}
|
||||
end.
|
||||
|
|
Loading…
Reference in New Issue