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}
]}. ]}.
@ -566,41 +566,43 @@ 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) ->
undefined -> Filter([{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
[]; {max_clients, cuttlefish:conf_get(Prefix ++ ".max_clients", Conf)},
TcpPort -> {rate_limt, cuttlefish:conf_get(Prefix ++ ".rate_limit", Conf, undefined)}])
TcpOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.tcp.acceptors", Conf)}, end,
{max_clients, cuttlefish:conf_get("mqtt.listener.tcp.max_clients", Conf)}, TcpOpts = fun(Prefix) ->
{rate_limt, cuttlefish:conf_get("mqtt.listener.tcp.rate_limit", Conf, undefined)}], Filter([{backlog, cuttlefish:conf_get(Prefix ++ ".backlog", Conf, undefined)},
[{tcp, TcpPort, Filter(TcpOpts)}] {recbuf, cuttlefish:conf_get(Prefix ++ ".recbuf", Conf, undefined)},
end, {sndbuf, cuttlefish:conf_get(Prefix ++ ".sndbuf", Conf, undefined)},
SslListeners = case cuttlefish:conf_get("mqtt.listener.ssl", Conf) of {buffer, cuttlefish:conf_get(Prefix ++ ".buffer", Conf, undefined)},
undefined -> {nodelay, cuttlefish:conf_get(Prefix ++ ".nodelay", Conf, true)}])
[]; end,
SslPort -> SslOpts = fun(Prefix) ->
SslOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.ssl.acceptors", Conf)}, Filter([{handshake_timeout, cuttlefish:conf_get(Prefix ++ ".handshake_timeout", Conf)},
{max_clients, cuttlefish:conf_get("mqtt.listener.ssl.max_clients", Conf)}], {keyfile, cuttlefish:conf_get(Prefix ++ ".keyfile", Conf, undefined)},
[{ssl, SslPort, Filter(SslOpts)}] {certfile, cuttlefish:conf_get(Prefix ++ ".certfile", Conf, undefined)},
end, {cacertfile, cuttlefish:conf_get(Prefix ++ ".cacertfile", Conf, undefined)},
HttpListeners = case cuttlefish:conf_get("mqtt.listener.http", Conf) of {verify, cuttlefish:conf_get(Prefix ++ ".verify_peer", Conf, undefined)},
undefined -> {failed_if_no_peer_cert, cuttlefish:conf_get(Prefix ++ "failed_if_no_peer_cert", Conf, undefined)}])
[]; end,
HttPort ->
HttpOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.http.acceptors", Conf)}, Listeners = fun(Name) when is_atom(Name) ->
{max_clients, cuttlefish:conf_get("mqtt.listener.http.max_clients", Conf)}], Key = "mqtt.listener." ++ atom_to_list(Name),
[{http, HttPort, Filter(HttpOpts)}] case cuttlefish:conf_get(Key, Conf, undefined) of
end, undefined ->
HttpsListeners = case cuttlefish:conf_get("mqtt.listener.https", Conf, undefined) of [];
undefined -> Port ->
[]; ConnOpts = Filter([{rate_limit, cuttlefish:conf_get(Key ++ ".rate_limit", Conf, undefined)}]),
HttsPort -> Opts = [{connopts, ConnOpts}, {sockopts, TcpOpts(Key)} | LisOpts(Key)],
HttpsOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.https.acceptors", Conf)}, [{Name, Port, case Name =:= ssl orelse Name =:= https of
{max_clients, cuttlefish:conf_get("mqtt.listener.https.max_clients", Conf)}], true -> [{ssl, SslOpts(Key)} | Opts];
[{https, HttsPort, Filter(HttpsOpts)}] false -> Opts
end, end}]
TcpListeners ++ SslListeners ++ HttpListeners ++ HttpsListeners end
end,
[Listeners(tcp), Listeners(ssl), Listeners(http), Listeners(https)]
end}. end}.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------