emqx 消息数据存储MySQL 插件源码分析(1)

华展鹏
2023-12-01

 1、emqx_backend_mysql_app模块 源码分析

-module(emqx_backend_mysql_app).
-include("mysql/include/emqx_backend_mysql.hrl").
-behaviour(application).
-emqx_plugin(backend).
-export([start/2, stop/1]).

start(_Type, _Args) ->
    %% 获取配置文件mysql的配置信息
    Pools = application:get_env(emqx_backend_mysql,pools,[]),
    %% 启动应用的root根监控
    {ok, Sup} = emqx_backend_mysql_sup:start_link(Pools),
    %% 注册
    emqx_backend_mysql:register_metrics(),
    %% 载入插件  
    emqx_backend_mysql:load(),
    {ok, Sup}.

%% 应用停止,卸载插件
stop(_State) -> emqx_backend_mysql:unload().

2、emqx_backend_mysql_sup 模块源码分析

-module(emqx_backend_mysql_sup).

-include("mysql/include/emqx_backend_mysql.hrl").
%% 监听者
-behaviour(supervisor).
-export([start_link/1]).
-export([init/1]).

%% 启动 mysql池
start_link(Pools) ->
    supervisor:start_link({local, emqx_backend_mysql_sup},
                       
 类似资料: