Improve listener config

This commit is contained in:
Feng Lee 2016-10-14 10:49:40 +08:00
parent 73659208a1
commit 9f391f1542
2 changed files with 46 additions and 56 deletions

View File

@ -2,7 +2,7 @@
## Node Args ## Node Args
##-------------------------------------------------------------------- ##--------------------------------------------------------------------
## Node Name ## Node name
node.name = emqttd@127.0.0.1 node.name = emqttd@127.0.0.1
## Cookie for distributed node ## Cookie for distributed node
@ -100,13 +100,13 @@ mqtt.session.max_awaiting_rel = 0
## Statistics Collection Interval(seconds) ## Statistics Collection Interval(seconds)
mqtt.session.collect_interval = 0 mqtt.session.collect_interval = 0
## Expired after 2 day: ## Expired after 1 day:
## w - week ## w - week
## d - day ## d - day
## h - hour ## h - hour
## m - minute ## m - minute
## s - second ## s - second
mqtt.session.expired_after = 2d mqtt.session.expired_after = 1d
##-------------------------------------------------------------------- ##--------------------------------------------------------------------
## MQTT Queue ## MQTT Queue
@ -167,7 +167,7 @@ mqtt.plugins.etc_dir = etc/plugins/
mqtt.plugins.loaded_file = data/loaded_plugins mqtt.plugins.loaded_file = data/loaded_plugins
##-------------------------------------------------------------------- ##--------------------------------------------------------------------
## TCP Listener ## MQTT Listeners
##-------------------------------------------------------------------- ##--------------------------------------------------------------------
## TCP Listener: 1883, 127.0.0.1:1883, ::1:1883 ## TCP Listener: 1883, 127.0.0.1:1883, ::1:1883
@ -189,10 +189,6 @@ mqtt.listener.tcp.backlog = 1024
## mqtt.listener.tcp.buffer = 4096 ## mqtt.listener.tcp.buffer = 4096
## mqtt.listener.tcp.nodelay = true ## mqtt.listener.tcp.nodelay = true
##--------------------------------------------------------------------
## SSL Listener
##--------------------------------------------------------------------
## SSL Listener: 8883, 127.0.0.1:8883, ::1:8883 ## SSL Listener: 8883, 127.0.0.1:8883, ::1:8883
mqtt.listener.ssl = 8883 mqtt.listener.ssl = 8883
@ -207,27 +203,19 @@ mqtt.listener.ssl.max_clients = 512
## Configuring SSL Options ## Configuring SSL Options
## See http://erlang.org/doc/man/ssl.html ## See http://erlang.org/doc/man/ssl.html
mqtt.listener.ssl.handshake_timeout = 10 #seconds mqtt.listener.ssl.handshake_timeout = 15 #seconds
## mqtt.listener.ssl.keyfile = /path/to/key.pem ## mqtt.listener.ssl.keyfile = etc/ssl/key.pem
## mqtt.listener.ssl.certfile = /path/to/cert.pem ## mqtt.listener.ssl.certfile = etc/ssl/cert.pem
## mqtt.listener.ssl.cacertfile = /path/to/cacert.pem ## mqtt.listener.ssl.cacertfile = etc/ssl/cacert.pem
## mqtt.listener.ssl.verify = verify_peer ## mqtt.listener.ssl.verify = verify_peer
## mqtt.listener.ssl.failed_if_no_peer_cert = true ## mqtt.listener.ssl.failed_if_no_peer_cert = true
##--------------------------------------------------------------------
## HTTP Listener ## HTTP Listener
##--------------------------------------------------------------------
mqtt.listener.http = 8083 mqtt.listener.http = 8083
mqtt.listener.http.acceptors = 4 mqtt.listener.http.acceptors = 4
mqtt.listener.http.max_clients = 64 mqtt.listener.http.max_clients = 64
##--------------------------------------------------------------------
## HTTP(SSL) Listener ## HTTP(SSL) Listener
##--------------------------------------------------------------------
## mqtt.listener.https = 8083 ## mqtt.listener.https = 8083
## mqtt.listener.https.acceptors = 4 ## mqtt.listener.https.acceptors = 4
## mqtt.listener.https.max_clients = 64 ## mqtt.listener.https.max_clients = 64

View File

@ -510,7 +510,7 @@ end}.
]}. ]}.
{mapping, "mqtt.listener.ssl.handshake_timeout", "emqttd.listeners", [ {mapping, "mqtt.listener.ssl.handshake_timeout", "emqttd.listeners", [
{default, 10}, {default, 15},
{datatype, integer} {datatype, integer}
]}. ]}.
@ -567,40 +567,42 @@ end}.
{translation, "emqttd.listeners", fun(Conf) -> {translation, "emqttd.listeners", fun(Conf) ->
Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end, Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end,
TcpListeners = case cuttlefish:conf_get("mqtt.listener.tcp", Conf) of LisOpts = fun(Prefix) ->
Filter([{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
{max_clients, cuttlefish:conf_get(Prefix ++ ".max_clients", Conf)},
{rate_limt, cuttlefish:conf_get(Prefix ++ ".rate_limit", Conf, undefined)}])
end,
TcpOpts = fun(Prefix) ->
Filter([{backlog, cuttlefish:conf_get(Prefix ++ ".backlog", Conf, undefined)},
{recbuf, cuttlefish:conf_get(Prefix ++ ".recbuf", Conf, undefined)},
{sndbuf, cuttlefish:conf_get(Prefix ++ ".sndbuf", Conf, undefined)},
{buffer, cuttlefish:conf_get(Prefix ++ ".buffer", Conf, undefined)},
{nodelay, cuttlefish:conf_get(Prefix ++ ".nodelay", Conf, true)}])
end,
SslOpts = fun(Prefix) ->
Filter([{handshake_timeout, cuttlefish:conf_get(Prefix ++ ".handshake_timeout", Conf)},
{keyfile, cuttlefish:conf_get(Prefix ++ ".keyfile", Conf, undefined)},
{certfile, cuttlefish:conf_get(Prefix ++ ".certfile", Conf, undefined)},
{cacertfile, cuttlefish:conf_get(Prefix ++ ".cacertfile", Conf, undefined)},
{verify, cuttlefish:conf_get(Prefix ++ ".verify_peer", Conf, undefined)},
{failed_if_no_peer_cert, cuttlefish:conf_get(Prefix ++ "failed_if_no_peer_cert", Conf, undefined)}])
end,
Listeners = fun(Name) when is_atom(Name) ->
Key = "mqtt.listener." ++ atom_to_list(Name),
case cuttlefish:conf_get(Key, Conf, undefined) of
undefined -> undefined ->
[]; [];
TcpPort -> Port ->
TcpOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.tcp.acceptors", Conf)}, ConnOpts = Filter([{rate_limit, cuttlefish:conf_get(Key ++ ".rate_limit", Conf, undefined)}]),
{max_clients, cuttlefish:conf_get("mqtt.listener.tcp.max_clients", Conf)}, Opts = [{connopts, ConnOpts}, {sockopts, TcpOpts(Key)} | LisOpts(Key)],
{rate_limt, cuttlefish:conf_get("mqtt.listener.tcp.rate_limit", Conf, undefined)}], [{Name, Port, case Name =:= ssl orelse Name =:= https of
[{tcp, TcpPort, Filter(TcpOpts)}] true -> [{ssl, SslOpts(Key)} | Opts];
false -> Opts
end}]
end
end, end,
SslListeners = case cuttlefish:conf_get("mqtt.listener.ssl", Conf) of [Listeners(tcp), Listeners(ssl), Listeners(http), Listeners(https)]
undefined ->
[];
SslPort ->
SslOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.ssl.acceptors", Conf)},
{max_clients, cuttlefish:conf_get("mqtt.listener.ssl.max_clients", Conf)}],
[{ssl, SslPort, Filter(SslOpts)}]
end,
HttpListeners = case cuttlefish:conf_get("mqtt.listener.http", Conf) of
undefined ->
[];
HttPort ->
HttpOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.http.acceptors", Conf)},
{max_clients, cuttlefish:conf_get("mqtt.listener.http.max_clients", Conf)}],
[{http, HttPort, Filter(HttpOpts)}]
end,
HttpsListeners = case cuttlefish:conf_get("mqtt.listener.https", Conf, undefined) of
undefined ->
[];
HttsPort ->
HttpsOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.https.acceptors", Conf)},
{max_clients, cuttlefish:conf_get("mqtt.listener.https.max_clients", Conf)}],
[{https, HttsPort, Filter(HttpsOpts)}]
end,
TcpListeners ++ SslListeners ++ HttpListeners ++ HttpsListeners
end}. end}.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------