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