fix(event_message): update config in cluster

This commit is contained in:
DDDHuang 2021-12-30 17:36:36 +08:00
parent 6c52fb4806
commit f0330d9334
3 changed files with 17 additions and 5 deletions

View File

@ -240,7 +240,7 @@ update_config_(Config) ->
{200, NewDelayed};
{error, Reason} ->
Message = list_to_binary(
io_lib:format("Update delayed message config failed ~p", [Reason])),
io_lib:format("Update config failed ~p", [Reason])),
{500, ?INTERNAL_ERROR, Message}
end.

View File

@ -44,8 +44,15 @@ list() ->
update(Params) ->
disable(),
{ok, _} = emqx:update_config([event_message], Params),
enable().
case emqx_conf:update([event_message],
Params,
#{rawconf_with_defaults => true, override_to => cluster}) of
{ok, #{config := NewEventMessage}} ->
enable(),
{ok, NewEventMessage};
{error, Reason} ->
{error, Reason}
end.
enable() ->
lists:foreach(fun({_Topic, false}) -> ok;

View File

@ -53,5 +53,10 @@ event_message(get, _Params) ->
{200, emqx_event_message:list()};
event_message(put, #{body := Body}) ->
_ = emqx_event_message:update(Body),
{200, emqx_event_message:list()}.
case emqx_event_message:update(Body) of
{ok, NewConfig} ->
{200, NewConfig};
{error, Reason} ->
Message = list_to_binary(io_lib:format("Update config failed ~p", [Reason])),
{500, 'INTERNAL_ERROR', Message}
end.