* feat(emqx_conf): move conf manager for emqx_machine to emqx_conf * chore(emqx_conf): change emqx:get_config/2 to emqx_conf:get/2 * fix: common test failed * fix: badmatch by typo wrong key * fix(emqx_conf): get the wrong core nodes * fix(emqx_conf): get core node's tnx_id not latest tnx_id * fix: add ro_transation when copy conf file * fix: delete debug info * fix: change ekka_rlog to mria_rlog * fix: remove cluster_rpc from emqx_machine. * fix: don't call ekka:start/0 explicitly * fix: ekka should be start in emqx_machine
84 lines
2.5 KiB
Erlang
84 lines
2.5 KiB
Erlang
%%--------------------------------------------------------------------
|
|
%% Copyright (c) 2020-2021 EMQ Technologies Co., Ltd. All Rights Reserved.
|
|
%%
|
|
%% Licensed under the Apache License, Version 2.0 (the "License");
|
|
%% you may not use this file except in compliance with the License.
|
|
%% You may obtain a copy of the License at
|
|
%%
|
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
%%
|
|
%% Unless required by applicable law or agreed to in writing, software
|
|
%% distributed under the License is distributed on an "AS IS" BASIS,
|
|
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
%% See the License for the specific language governing permissions and
|
|
%% limitations under the License.
|
|
%%--------------------------------------------------------------------
|
|
|
|
-module(emqx_exhook_sup).
|
|
|
|
-behaviour(supervisor).
|
|
|
|
-export([ start_link/0
|
|
, init/1
|
|
]).
|
|
|
|
-export([ start_grpc_client_channel/3
|
|
, stop_grpc_client_channel/1
|
|
]).
|
|
|
|
-define(CHILD(Mod, Type, Args),
|
|
#{ id => Mod
|
|
, start => {Mod, start_link, Args}
|
|
, type => Type
|
|
, shutdown => 15000
|
|
}
|
|
).
|
|
|
|
%%--------------------------------------------------------------------
|
|
%% Supervisor APIs & Callbacks
|
|
%%--------------------------------------------------------------------
|
|
|
|
start_link() ->
|
|
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
|
|
|
init([]) ->
|
|
Mngr = ?CHILD(emqx_exhook_mngr, worker,
|
|
[servers(), auto_reconnect(), request_options()]),
|
|
{ok, {{one_for_one, 10, 100}, [Mngr]}}.
|
|
|
|
servers() ->
|
|
env(servers, []).
|
|
|
|
auto_reconnect() ->
|
|
env(auto_reconnect, 60000).
|
|
|
|
request_options() ->
|
|
#{timeout => env(request_timeout, 5000),
|
|
request_failed_action => env(request_failed_action, deny)
|
|
}.
|
|
|
|
env(Key, Def) ->
|
|
emqx_conf:get([exhook, Key], Def).
|
|
|
|
%%--------------------------------------------------------------------
|
|
%% APIs
|
|
%%--------------------------------------------------------------------
|
|
|
|
-spec start_grpc_client_channel(
|
|
binary(),
|
|
uri_string:uri_string(),
|
|
grpc_client:options()) -> {ok, pid()} | {error, term()}.
|
|
start_grpc_client_channel(Name, SvrAddr, Options) ->
|
|
grpc_client_sup:create_channel_pool(Name, SvrAddr, Options).
|
|
|
|
-spec stop_grpc_client_channel(binary()) -> ok.
|
|
stop_grpc_client_channel(Name) ->
|
|
%% Avoid crash due to hot-upgrade had unloaded
|
|
%% grpc application
|
|
try
|
|
grpc_client_sup:stop_channel_pool(Name)
|
|
catch
|
|
_:_:_ ->
|
|
ok
|
|
end.
|