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

Commit 5e9e067

Browse files
Don't include max_connections into socket options
It is rejected as an unsupported value. Use Ranch transport options directly instead. References #28. Closes #55.
1 parent 38e50a1 commit 5e9e067

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

priv/schema/rabbitmq_web_mqtt.schema

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
[{datatype, integer}]}.
33
{mapping, "web_mqtt.num_acceptors.ssl", "rabbitmq_web_mqtt.num_ssl_acceptors",
44
[{datatype, integer}]}.
5+
{mapping, "web_mqtt.max_connections", "rabbitmq_web_mqtt.max_connections", [
6+
{datatype, [{enum, [infinity]}, integer]}
7+
]}.
58

69
{mapping, "web_mqtt.tcp.backlog", "rabbitmq_web_mqtt.tcp_config.backlog",
710
[{datatype, integer}]}.
@@ -12,9 +15,6 @@
1215
[{datatype, string}, {validators, ["is_ip"]}]}.
1316
{mapping, "web_mqtt.tcp.port", "rabbitmq_web_mqtt.tcp_config.port",
1417
[{datatype, integer}]}.
15-
{mapping, "web_mqtt.tcp.max_connections", "rabbitmq_web_mqtt.tcp_config.max_connections", [
16-
{datatype, [{enum, [infinity]}, integer]}
17-
]}.
1818

1919
{mapping, "web_mqtt.ws_path", "rabbitmq_web_mqtt.ws_path",
2020
[{datatype, string}]}.

src/rabbit_web_mqtt_app.erl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ mqtt_init() ->
6666

6767
start_tcp_listener(TCPConf0, CowboyOpts) ->
6868
{TCPConf, IpStr, Port} = get_tcp_conf(TCPConf0),
69+
MaxConnections = get_max_connections(),
6970
case ranch:start_listener(web_mqtt, get_env(num_tcp_acceptors, 10),
70-
ranch_tcp, TCPConf,
71+
ranch_tcp, [{max_connections, MaxConnections}|TCPConf],
7172
rabbit_web_mqtt_connection_sup, CowboyOpts) of
7273
{ok, _} -> ok;
7374
{error, {already_started, _}} -> ok;
@@ -85,11 +86,12 @@ start_tcp_listener(TCPConf0, CowboyOpts) ->
8586
start_tls_listener(TLSConf0, CowboyOpts) ->
8687
rabbit_networking:ensure_ssl(),
8788
{TLSConf, TLSIpStr, TLSPort} = get_tls_conf(TLSConf0),
89+
MaxConnections = get_max_connections(),
8890
{ok, _} = ranch:start_listener(web_mqtt_secure, get_env(num_ssl_acceptors, 10),
89-
ranch_ssl, TLSConf,
91+
ranch_ssl, [{max_connections, MaxConnections}|TLSConf],
9092
rabbit_web_mqtt_connection_sup, CowboyOpts),
9193
case ranch:start_listener(web_mqtt_secure, get_env(num_ssl_acceptors, 10),
92-
ranch_ssl, TLSConf,
94+
ranch_ssl, [{max_connections, MaxConnections}|TLSConf],
9395
rabbit_web_mqtt_connection_sup, CowboyOpts) of
9496
{ok, _} -> ok;
9597
{error, {already_started, _}} -> ok;
@@ -113,19 +115,15 @@ listener_started(Protocol, Listener) ->
113115
ok.
114116

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

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

146+
get_max_connections() ->
147+
get_env(max_connections, infinity).
148+
148149
get_env(Key, Default) ->
149150
rabbit_misc:get_env(rabbitmq_web_mqtt, Key, Default).

test/config_schema_SUITE_data/rabbitmq_web_mqtt.snippets

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,23 @@
2929
[{rabbitmq_web_mqtt,
3030
[{tcp_config, [{port,34567}]}]}],
3131
[rabbitmq_web_mqtt]},
32-
{tcp_config_max_connections,
33-
"web_mqtt.tcp.max_connections = 5000",
32+
33+
{num_acceptors_tcp,
34+
"web_mqtt.num_acceptors.tcp = 20",
35+
[{rabbitmq_web_mqtt,
36+
[{num_tcp_acceptors, 20}]}],
37+
[rabbitmq_web_mqtt]},
38+
39+
{num_acceptors_tls,
40+
"web_mqtt.num_acceptors.ssl = 20",
41+
[{rabbitmq_web_mqtt,
42+
[{num_ssl_acceptors, 20}]}],
43+
[rabbitmq_web_mqtt]},
44+
45+
{max_connections,
46+
"web_mqtt.max_connections = 5000",
3447
[{rabbitmq_web_mqtt,
35-
[{tcp_config, [{max_connections, 5000}]}]}],
48+
[{max_connections, 5000}]}],
3649
[rabbitmq_web_mqtt]},
3750

3851
{ssl_listener,

0 commit comments

Comments
 (0)