improve conf design
This commit is contained in:
parent
edb45d7029
commit
7e41bc9091
|
@ -53,7 +53,7 @@
|
||||||
-define(APP, ?MODULE).
|
-define(APP, ?MODULE).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Bootstrap, environment, configuration, is_running...
|
%% Bootstrap, environment, is_running...
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
%% @doc Start emqttd application.
|
%% @doc Start emqttd application.
|
||||||
|
|
|
@ -16,84 +16,91 @@
|
||||||
|
|
||||||
-module(emqttd_conf).
|
-module(emqttd_conf).
|
||||||
|
|
||||||
-export([mqtt/0, retained/0, session/0, queue/0, bridge/0, pubsub/0]).
|
-import(gen_conf, [value/3]).
|
||||||
|
|
||||||
|
-export([mqtt/0, session/0, queue/0, bridge/0, pubsub/0]).
|
||||||
|
|
||||||
|
-export([list/1]).
|
||||||
|
|
||||||
|
-define(APP, emqttd).
|
||||||
|
|
||||||
mqtt() ->
|
mqtt() ->
|
||||||
[
|
with_env(mqtt_protocol, [
|
||||||
%% Max ClientId Length Allowed.
|
%% Max ClientId Length Allowed.
|
||||||
{max_clientid_len, emqttd:conf(mqtt_max_clientid_len, 512)},
|
{max_clientid_len, value(?APP, mqtt_max_clientid_len, 512)},
|
||||||
%% Max Packet Size Allowed, 64K by default.
|
%% Max Packet Size Allowed, 64K by default.
|
||||||
{max_packet_size, emqttd:conf(mqtt_max_packet_size, 65536)},
|
{max_packet_size, value(?APP, mqtt_max_packet_size, 65536)},
|
||||||
%% Client Idle Timeout.
|
%% Client Idle Timeout.
|
||||||
{client_idle_timeout, emqttd:conf(mqtt_client_idle_timeout, 30)}
|
{client_idle_timeout, value(?APP, mqtt_client_idle_timeout, 30)}
|
||||||
].
|
]).
|
||||||
|
|
||||||
retained() ->
|
|
||||||
[
|
|
||||||
%% Expired after seconds, never expired if 0
|
|
||||||
{expired_after, emqttd:conf(retained_expired_after, 0)},
|
|
||||||
%% Max number of retained messages
|
|
||||||
{max_message_num, emqttd:conf(retained_max_message_num, 100000)},
|
|
||||||
%% Max Payload Size of retained message
|
|
||||||
{max_playload_size, emqttd:conf(retained_max_playload_size, 65536)}
|
|
||||||
].
|
|
||||||
|
|
||||||
session() ->
|
session() ->
|
||||||
[
|
with_env(mqtt_session, [
|
||||||
%% Max number of QoS 1 and 2 messages that can be “inflight” at one time.
|
%% Max number of QoS 1 and 2 messages that can be “inflight” at one time.
|
||||||
%% 0 means no limit
|
%% 0 means no limit
|
||||||
{max_inflight, emqttd:conf(session_max_inflight, 100)},
|
{max_inflight, value(?APP, session_max_inflight, 100)},
|
||||||
|
|
||||||
%% Retry interval for redelivering QoS1/2 messages.
|
%% Retry interval for redelivering QoS1/2 messages.
|
||||||
{unack_retry_interval, emqttd:conf(session_unack_retry_interval, 60)},
|
{unack_retry_interval, value(?APP, session_unack_retry_interval, 60)},
|
||||||
|
|
||||||
%% Awaiting PUBREL Timeout
|
%% Awaiting PUBREL Timeout
|
||||||
{await_rel_timeout, emqttd:conf(session_await_rel_timeout, 20)},
|
{await_rel_timeout, value(?APP, session_await_rel_timeout, 20)},
|
||||||
|
|
||||||
%% Max Packets that Awaiting PUBREL, 0 means no limit
|
%% Max Packets that Awaiting PUBREL, 0 means no limit
|
||||||
{max_awaiting_rel, emqttd:conf(session_max_awaiting_rel, 0)},
|
{max_awaiting_rel, value(?APP, session_max_awaiting_rel, 0)},
|
||||||
|
|
||||||
%% Statistics Collection Interval(seconds)
|
%% Statistics Collection Interval(seconds)
|
||||||
{collect_interval, emqttd:conf(session_collect_interval, 0)},
|
{collect_interval, value(?APP, session_collect_interval, 0)},
|
||||||
|
|
||||||
%% Expired after 2 day (unit: minute)
|
%% Expired after 2 day (unit: minute)
|
||||||
{expired_after, emqttd:conf(session_expired_after, 2880)}
|
{expired_after, value(?APP, session_expired_after, 2880)}
|
||||||
].
|
]).
|
||||||
|
|
||||||
queue() ->
|
queue() ->
|
||||||
[
|
with_env(mqtt_queue, [
|
||||||
%% Type: simple | priority
|
%% Type: simple | priority
|
||||||
{type, emqttd:conf(queue_type, simple)},
|
{type, value(?APP, queue_type, simple)},
|
||||||
|
|
||||||
%% Topic Priority: 0~255, Default is 0
|
%% Topic Priority: 0~255, Default is 0
|
||||||
{priority, emqttd:conf(queue_priority, [])},
|
{priority, value(?APP, queue_priority, [])},
|
||||||
|
|
||||||
%% Max queue length. Enqueued messages when persistent client disconnected,
|
%% Max queue length. Enqueued messages when persistent client disconnected,
|
||||||
%% or inflight window is full.
|
%% or inflight window is full.
|
||||||
{max_length, emqttd:conf(queue_max_length, infinity)},
|
{max_length, value(?APP, queue_max_length, infinity)},
|
||||||
|
|
||||||
%% Low-water mark of queued messages
|
%% Low-water mark of queued messages
|
||||||
{low_watermark, emqttd:conf(queue_low_watermark, 0.2)},
|
{low_watermark, value(?APP, queue_low_watermark, 0.2)},
|
||||||
|
|
||||||
%% High-water mark of queued messages
|
%% High-water mark of queued messages
|
||||||
{high_watermark, emqttd:conf(queue_high_watermark, 0.6)},
|
{high_watermark, value(?APP, queue_high_watermark, 0.6)},
|
||||||
|
|
||||||
%% Queue Qos0 messages?
|
%% Queue Qos0 messages?
|
||||||
{queue_qos0, emqttd:conf(queue_qos0, true)}
|
{queue_qos0, value(?APP, queue_qos0, true)}
|
||||||
].
|
]).
|
||||||
|
|
||||||
bridge() ->
|
bridge() ->
|
||||||
[
|
with_env(mqtt_bridge, [
|
||||||
%% TODO: Bridge Queue Size
|
%% TODO: Bridge Queue Size
|
||||||
{max_queue_len, emqttd:conf(bridge_max_queue_len, 10000)},
|
{max_queue_len, value(?APP, bridge_max_queue_len, 10000)},
|
||||||
|
|
||||||
%% Ping Interval of bridge node
|
%% Ping Interval of bridge node
|
||||||
{ping_down_interval, emqttd:conf(bridge_ping_down_interval, 1)}
|
{ping_down_interval, value(?APP, bridge_ping_down_interval, 1)}
|
||||||
].
|
]).
|
||||||
|
|
||||||
pubsub() ->
|
pubsub() ->
|
||||||
[
|
with_env(mqtt_pubsub, [
|
||||||
%% PubSub and Router. Default should be scheduler numbers.
|
%% PubSub and Router. Default should be scheduler numbers.
|
||||||
{pool_size, emqttd:conf(pubsub_pool_size, 8)}
|
{pool_size, value(?APP, pubsub_pool_size, 8)}
|
||||||
].
|
]).
|
||||||
|
|
||||||
|
with_env(Key, Conf) ->
|
||||||
|
case application:get_env(?APP, Key) of
|
||||||
|
undefined ->
|
||||||
|
application:set_env(?APP, Key, Conf), Conf;
|
||||||
|
{ok, Val} ->
|
||||||
|
Val
|
||||||
|
end.
|
||||||
|
|
||||||
|
list(Key) ->
|
||||||
|
gen_conf:list(?APP, Key).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue