remove modules

This commit is contained in:
Feng 2016-10-31 20:26:56 +08:00
parent 031a288b50
commit eb9c11f321
4 changed files with 2 additions and 138 deletions

View File

@ -169,37 +169,6 @@ mqtt.plugins.etc_dir = etc/plugins/
## File to store loaded plugin names. ## File to store loaded plugin names.
mqtt.plugins.loaded_file = data/loaded_plugins mqtt.plugins.loaded_file = data/loaded_plugins
##-------------------------------------------------------------------
## MQTT Modules
##-------------------------------------------------------------------
## Enable retainer module
mqtt.module.retainer = on
## disc: disc_copies, ram: ram_copies
mqtt.module.retainer.storage_type = ram
## Max number of retained messages
mqtt.module.retainer.max_message_num = 100000
## Max Payload Size of retained message
mqtt.module.retainer.max_payload_size = 64KB
## Expired after seconds, never expired if 0
mqtt.module.retainer.expired_after = 0
## Enable presence module
## Publish presence messages when client connected or disconnected.
mqtt.module.presence = on
mqtt.module.presence.qos = 0
## Enable subscription module
## Subscribe topics automatically when client connected
mqtt.module.subscription = on
mqtt.module.subscription.topics = $client/%c=1,$user/%u=1
##-------------------------------------------------------------------- ##--------------------------------------------------------------------
## MQTT Listeners ## MQTT Listeners
##-------------------------------------------------------------------- ##--------------------------------------------------------------------

View File

@ -636,83 +636,6 @@ end}.
lists:append([Listeners(tcp), Listeners(ssl), Listeners(http), Listeners(https)]) lists:append([Listeners(tcp), Listeners(ssl), Listeners(http), Listeners(https)])
end}. end}.
%%--------------------------------------------------------------------
%% MQTT Modules
%%--------------------------------------------------------------------
{mapping, "mqtt.module.retainer", "emqttd.modules", [
{default, on},
{datatype, flag}
]}.
{mapping, "mqtt.module.retainer.storage_type", "emqttd.modules", [
{default, ram},
{datatype, {enum, [disc, ram]}}
]}.
{mapping, "mqtt.module.retainer.max_message_num", "emqttd.modules", [
{default, 100000},
{datatype, integer}
]}.
{mapping, "mqtt.module.retainer.max_payload_size", "emqttd.modules", [
{default, "64KB"},
{datatype, bytesize}
]}.
{mapping, "mqtt.module.retainer.expired_after", "emqttd.modules", [
{default, 0},
{datatype, integer}
]}.
{mapping, "mqtt.module.presence", "emqttd.modules", [
{default, on},
{datatype, flag}
]}.
{mapping, "mqtt.module.presence.qos", "emqttd.modules", [
{default, 0},
{datatype, integer},
{validators, ["range:0-2"]}
]}.
{mapping, "mqtt.module.subscription", "emqttd.modules", [
{default, off},
{datatype, flag}
]}.
{mapping, "mqtt.module.subscription.topics", "emqttd.modules", [
{default, undefined},
{datatype, string}
]}.
{translation, "emqttd.modules", fun(Conf) ->
WithMod = fun(Name, OptsF) ->
Key = "mqtt.module." ++ atom_to_list(Name),
case cuttlefish:conf_get(Key, Conf, false) of
true -> [{Name, OptsF(Key)}];
false -> []
end
end,
RetainOpts = fun(Prefix) ->
[{storage_type, cuttlefish:conf_get(Prefix ++ ".storage_type", Conf, ram)},
{max_message_num, cuttlefish:conf_get(Prefix ++ ".max_message_num", Conf, undefined)},
{max_payload_size, cuttlefish:conf_get(Prefix ++ ".max_payload_size", Conf, undefined)},
{expired_after, cuttlefish:conf_get(Prefix ++ ".expired_after", Conf, 0)}]
end,
PresOpts = fun(Prefix) ->
[{qos, cuttlefish:conf_get(Prefix ++ ".qos", Conf, 0)}]
end,
ParseFun = fun(undefined) -> [];
(Topics) -> [begin
[Topic, Qos] = string:tokens(S, "="),
{list_to_binary(Topic), list_to_integer(Qos)}
end || S <- string:tokens(Topics, ",")]
end,
SubOpts = fun(Prefix) -> ParseFun(cuttlefish:conf_get(Prefix ++ ".topics", Conf)) end,
lists:append([WithMod(retainer, RetainOpts), WithMod(presence, PresOpts), WithMod(subscription, SubOpts)])
end}.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% System Monitor %% System Monitor
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------

View File

@ -1,4 +1,4 @@
{deps, [ {deps, [
{gproc,".*",{git,"https://github.com/uwiger/gproc",""}},{lager,".*",{git,"https://github.com/basho/lager","master"}},{gen_logger,".*",{git,"https://github.com/emqtt/gen_logger",""}},{esockd,".*",{git,"https://github.com/emqtt/esockd","emq20"}},{mochiweb,".*",{git,"https://github.com/emqtt/mochiweb",""}},{getopt,".*",{git,"https://github.com/jcomellas/getopt","v0.8.2"}},{pbkdf2,".*",{git,"https://github.com/basho/erlang-pbkdf2","2.0.0"}},{clique,".*",{git,"https://github.com/basho/clique",""}},{time_compat,".*",{git,"https://github.com/lasp-lang/time_compat",""}},{rand_compat,".*",{git,"https://github.com/lasp-lang/rand_compat",""}} {gproc,".*",{git,"https://github.com/uwiger/gproc",""}},{lager,".*",{git,"https://github.com/basho/lager","master"}},{gen_logger,".*",{git,"https://github.com/emqtt/gen_logger",""}},{esockd,".*",{git,"https://github.com/emqtt/esockd","emq20"}},{mochiweb,".*",{git,"https://github.com/emqtt/mochiweb",""}}
]}. ]}.
{erl_opts, [{parse_transform,lager_transform}]}. {erl_opts, [{parse_transform,lager_transform}]}.

View File

@ -23,7 +23,7 @@
%% Application callbacks %% Application callbacks
-export([start/2, stop/1]). -export([start/2, stop/1]).
-export([start_listener/1, stop_listener/1, is_mod_enabled/1]). -export([start_listener/1, stop_listener/1]).
%% MQTT SockOpts %% MQTT SockOpts
-define(MQTT_SOCKOPTS, [binary, {packet, raw}, {reuseaddr, true}, -define(MQTT_SOCKOPTS, [binary, {packet, raw}, {reuseaddr, true},
@ -47,7 +47,6 @@ start(_StartType, _StartArgs) ->
start_servers(Sup), start_servers(Sup),
emqttd_cli:load(), emqttd_cli:load(),
register_acl_mod(), register_acl_mod(),
load_all_mods(),
emqttd_plugins:init(), emqttd_plugins:init(),
emqttd_plugins:load(), emqttd_plugins:load(),
start_listeners(), start_listeners(),
@ -151,26 +150,6 @@ register_acl_mod() ->
undefined -> ok undefined -> ok
end. end.
%%--------------------------------------------------------------------
%% Load Modules
%%--------------------------------------------------------------------
%% @doc Load all modules
load_all_mods() ->
lists:foreach(fun load_mod/1, emqttd:env(modules, [])).
load_mod({Name, Opts}) ->
Mod = list_to_atom("emqttd_mod_" ++ atom_to_list(Name)),
case catch Mod:load(Opts) of
ok -> lager:info("Load module ~s successfully", [Name]);
{error, Error} -> lager:error("Load module ~s error: ~p", [Name, Error]);
{'EXIT', Reason} -> lager:error("Load module ~s error: ~p", [Name, Reason])
end.
%% @doc Is module enabled?
-spec(is_mod_enabled(Name :: atom()) -> boolean()).
is_mod_enabled(Name) -> lists:keyfind(Name, 1, emqttd:env(modules, [])).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Start Listeners %% Start Listeners
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -231,11 +210,4 @@ merge_sockopts_test_() ->
Opts = [{acceptors, 16}, {max_clients, 512}], Opts = [{acceptors, 16}, {max_clients, 512}],
?_assert(merge_sockopts(Opts) == [{sockopts, ?MQTT_SOCKOPTS} | Opts]). ?_assert(merge_sockopts(Opts) == [{sockopts, ?MQTT_SOCKOPTS} | Opts]).
load_all_mods_test_() ->
?_assert(load_all_mods() == ok).
is_mod_enabled_test_() ->
?_assert(is_mod_enabled(presence) == {module, presence, [{qos, 0}]}),
?_assert(is_mod_enabled(test) == false).
-endif. -endif.