Merge pull request #7266 from lafirest/fix/topic_rewrite
fix(rewrite): fix config update maybe not work
This commit is contained in:
commit
40f0f61744
|
@ -52,9 +52,7 @@ enable() ->
|
||||||
|
|
||||||
disable() ->
|
disable() ->
|
||||||
emqx_conf:remove_handler([rewrite]),
|
emqx_conf:remove_handler([rewrite]),
|
||||||
emqx_hooks:del('client.subscribe', {?MODULE, rewrite_subscribe}),
|
unregister_hook(),
|
||||||
emqx_hooks:del('client.unsubscribe', {?MODULE, rewrite_unsubscribe}),
|
|
||||||
emqx_hooks:del('message.publish', {?MODULE, rewrite_publish}),
|
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
list() ->
|
list() ->
|
||||||
|
@ -67,7 +65,7 @@ update(Rules0) ->
|
||||||
post_config_update(_KeyPath, _Config, Rules, _OldConf, _AppEnvs) ->
|
post_config_update(_KeyPath, _Config, Rules, _OldConf, _AppEnvs) ->
|
||||||
register_hook(Rules).
|
register_hook(Rules).
|
||||||
|
|
||||||
register_hook([]) -> disable();
|
register_hook([]) -> unregister_hook();
|
||||||
register_hook(Rules) ->
|
register_hook(Rules) ->
|
||||||
{PubRules, SubRules, ErrRules} = compile(Rules),
|
{PubRules, SubRules, ErrRules} = compile(Rules),
|
||||||
emqx_hooks:put('client.subscribe', {?MODULE, rewrite_subscribe, [SubRules]}),
|
emqx_hooks:put('client.subscribe', {?MODULE, rewrite_subscribe, [SubRules]}),
|
||||||
|
@ -80,6 +78,11 @@ register_hook(Rules) ->
|
||||||
{error, ErrRules}
|
{error, ErrRules}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
unregister_hook() ->
|
||||||
|
emqx_hooks:del('client.subscribe', {?MODULE, rewrite_subscribe}),
|
||||||
|
emqx_hooks:del('client.unsubscribe', {?MODULE, rewrite_unsubscribe}),
|
||||||
|
emqx_hooks:del('message.publish', {?MODULE, rewrite_publish}).
|
||||||
|
|
||||||
rewrite_subscribe(_ClientInfo, _Properties, TopicFilters, Rules) ->
|
rewrite_subscribe(_ClientInfo, _Properties, TopicFilters, Rules) ->
|
||||||
{ok, [{match_and_rewrite(Topic, Rules), Opts} || {Topic, Opts} <- TopicFilters]}.
|
{ok, [{match_and_rewrite(Topic, Rules), Opts} || {Topic, Opts} <- TopicFilters]}.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue