Skip to content
This repository has been archived by the owner on Nov 16, 2020. It is now read-only.

Commit

Permalink
Don't include max_connections into socket options
Browse files Browse the repository at this point in the history
It is rejected as an unsupported value.
Use Ranch transport options directly instead.

References #28.
Closes #55.
  • Loading branch information
michaelklishin committed Jun 7, 2019
1 parent 38e50a1 commit 5e9e067
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
6 changes: 3 additions & 3 deletions priv/schema/rabbitmq_web_mqtt.schema
Expand Up @@ -2,6 +2,9 @@
[{datatype, integer}]}.
{mapping, "web_mqtt.num_acceptors.ssl", "rabbitmq_web_mqtt.num_ssl_acceptors",
[{datatype, integer}]}.
{mapping, "web_mqtt.max_connections", "rabbitmq_web_mqtt.max_connections", [
{datatype, [{enum, [infinity]}, integer]}
]}.

{mapping, "web_mqtt.tcp.backlog", "rabbitmq_web_mqtt.tcp_config.backlog",
[{datatype, integer}]}.
Expand All @@ -12,9 +15,6 @@
[{datatype, string}, {validators, ["is_ip"]}]}.
{mapping, "web_mqtt.tcp.port", "rabbitmq_web_mqtt.tcp_config.port",
[{datatype, integer}]}.
{mapping, "web_mqtt.tcp.max_connections", "rabbitmq_web_mqtt.tcp_config.max_connections", [
{datatype, [{enum, [infinity]}, integer]}
]}.

{mapping, "web_mqtt.ws_path", "rabbitmq_web_mqtt.ws_path",
[{datatype, string}]}.
Expand Down
19 changes: 10 additions & 9 deletions src/rabbit_web_mqtt_app.erl
Expand Up @@ -66,8 +66,9 @@ mqtt_init() ->

start_tcp_listener(TCPConf0, CowboyOpts) ->
{TCPConf, IpStr, Port} = get_tcp_conf(TCPConf0),
MaxConnections = get_max_connections(),
case ranch:start_listener(web_mqtt, get_env(num_tcp_acceptors, 10),
ranch_tcp, TCPConf,
ranch_tcp, [{max_connections, MaxConnections}|TCPConf],
rabbit_web_mqtt_connection_sup, CowboyOpts) of
{ok, _} -> ok;
{error, {already_started, _}} -> ok;
Expand All @@ -85,11 +86,12 @@ start_tcp_listener(TCPConf0, CowboyOpts) ->
start_tls_listener(TLSConf0, CowboyOpts) ->
rabbit_networking:ensure_ssl(),
{TLSConf, TLSIpStr, TLSPort} = get_tls_conf(TLSConf0),
MaxConnections = get_max_connections(),
{ok, _} = ranch:start_listener(web_mqtt_secure, get_env(num_ssl_acceptors, 10),
ranch_ssl, TLSConf,
ranch_ssl, [{max_connections, MaxConnections}|TLSConf],
rabbit_web_mqtt_connection_sup, CowboyOpts),
case ranch:start_listener(web_mqtt_secure, get_env(num_ssl_acceptors, 10),
ranch_ssl, TLSConf,
ranch_ssl, [{max_connections, MaxConnections}|TLSConf],
rabbit_web_mqtt_connection_sup, CowboyOpts) of
{ok, _} -> ok;
{error, {already_started, _}} -> ok;
Expand All @@ -113,19 +115,15 @@ listener_started(Protocol, Listener) ->
ok.

get_tcp_conf(TCPConf0) ->
TCPConf1 = [{connection_type, supervisor},
%% see rabbitmq/rabbitmq-web-mqtt#28 for background
{max_connections, infinity}] ++ TCPConf0,
TCPConf1 = [{connection_type, supervisor}|TCPConf0],
TCPConf2 = case proplists:get_value(port, TCPConf1) of
undefined -> [{port, 15675}|TCPConf1];
_ -> TCPConf1
end,
get_ip_port(TCPConf2).

get_tls_conf(TLSConf0) ->
TLSConf1 = [{connection_type, supervisor},
%% see rabbitmq/rabbitmq-web-mqtt#28 for background
{max_connections, infinity}] ++ TLSConf0,
TLSConf1 = [{connection_type, supervisor}|TLSConf0],
TLSConf2 = case proplists:get_value(port, TLSConf1) of
undefined -> [{port, 15675}|proplists:delete(port, TLSConf1)];
_ -> TLSConf1
Expand All @@ -145,5 +143,8 @@ normalize_ip(IpStr) when is_list(IpStr) ->
normalize_ip(Ip) ->
Ip.

get_max_connections() ->
get_env(max_connections, infinity).

get_env(Key, Default) ->
rabbit_misc:get_env(rabbitmq_web_mqtt, Key, Default).
19 changes: 16 additions & 3 deletions test/config_schema_SUITE_data/rabbitmq_web_mqtt.snippets
Expand Up @@ -29,10 +29,23 @@
[{rabbitmq_web_mqtt,
[{tcp_config, [{port,34567}]}]}],
[rabbitmq_web_mqtt]},
{tcp_config_max_connections,
"web_mqtt.tcp.max_connections = 5000",

{num_acceptors_tcp,
"web_mqtt.num_acceptors.tcp = 20",
[{rabbitmq_web_mqtt,
[{num_tcp_acceptors, 20}]}],
[rabbitmq_web_mqtt]},

{num_acceptors_tls,
"web_mqtt.num_acceptors.ssl = 20",
[{rabbitmq_web_mqtt,
[{num_ssl_acceptors, 20}]}],
[rabbitmq_web_mqtt]},

{max_connections,
"web_mqtt.max_connections = 5000",
[{rabbitmq_web_mqtt,
[{tcp_config, [{max_connections, 5000}]}]}],
[{max_connections, 5000}]}],
[rabbitmq_web_mqtt]},

{ssl_listener,
Expand Down

0 comments on commit 5e9e067

Please sign in to comment.