插件相关的一些代码
msiot_emqx_bridge_sup.erl
-module(msiot_emqx_bridge_sup).
-behaviour(supervisor).
-export([start_link/0]).
-export([init/1]).
start_link() ->
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
init([]) ->
PulsarClientSpec = #{id => iotms_pulsar_client,
start => {iotms_pulsar_client, start_link, [iotms_pulsar_client, {}]},
restart => transient,
type => worker,
modules => [iotms_pulsar_client]
},
{ok, { {one_for_all, 0, 1}, [PulsarClientSpec]} }.
msiot_emqx_bridge_app.erl
-module(msiot_emqx_bridge_app).
-behaviour(application).
-emqx_plugin(?MODULE).
-export([ start/2
, stop/1
]).
start(_StartType, _StartArgs) ->
%% 载入配置文件中配置项
ok = iotms_config:load(),
{ok, Sup} = msiot_emqx_bridge_sup:start_link(),
msiot_emqx_bridge:load(application:get_all_env()),
emqx_ctl:register_command(msiot_emqx_bridge, {msiot_emqx_bridge_cli, cmd}),
{ok, Sup}.
stop(_State) ->
emqx_ctl:unregister_command(msiot_emqx_bridge),
msiot_emqx_bridge:unload().
msiot_emqx_bridge.erl
-module(msiot_emqx_bridge).
register_metrics() ->
emqx_metrics:new('ms_pulsar_bridge.client_connected'),
emqx_metrics:new('ms_pulsar_bridge.client_disconnected'),
emqx_metrics:new('ms_pulsar_bridge.message_publish'),
emqx_metrics:new('ms_pulsar_bridge.message_overflow'),
emqx_metrics:new('ms_pulsar_bridge.message_failed'),
ok.
load(Env) ->
ok = register_metrics(),
hook('client.connected', {?MODULE, on_client_connected, [Env]}),
hook('client.disconnected', {?MODULE, on_client_disconnected, [Env]}),
hook('message.publish', {?MODULE, on_message_publish, [Env]}).