|
|
@@ -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}.
|
|
|
|