Add feature for issue#1809
This commit is contained in:
parent
5b47df1631
commit
d29069a50d
|
@ -1207,6 +1207,11 @@ listener.ssl.external.reuseaddr = true
|
||||||
## Examples: 8083, 127.0.0.1:8083, ::1:8083
|
## Examples: 8083, 127.0.0.1:8083, ::1:8083
|
||||||
listener.ws.external = 8083
|
listener.ws.external = 8083
|
||||||
|
|
||||||
|
## Whether the client must include "mqtt" in the list of WebSocket Sub Protocols it offers
|
||||||
|
##
|
||||||
|
## Value: true | false
|
||||||
|
listener.ws.external.standard_mqtt = true
|
||||||
|
|
||||||
## The acceptor pool for external MQTT/WebSocket listener.
|
## The acceptor pool for external MQTT/WebSocket listener.
|
||||||
##
|
##
|
||||||
## Value: Number
|
## Value: Number
|
||||||
|
@ -1346,6 +1351,11 @@ listener.ws.external.nodelay = true
|
||||||
## Examples: 8084, 127.0.0.1:8084, ::1:8084
|
## Examples: 8084, 127.0.0.1:8084, ::1:8084
|
||||||
listener.wss.external = 8084
|
listener.wss.external = 8084
|
||||||
|
|
||||||
|
## Whether the client must include "mqtt" in the list of WebSocket Sub Protocols it offers
|
||||||
|
##
|
||||||
|
## Value: true | false
|
||||||
|
listener.wss.external.standard_mqtt = true
|
||||||
|
|
||||||
## The acceptor pool for external MQTT/WebSocket/SSL listener.
|
## The acceptor pool for external MQTT/WebSocket/SSL listener.
|
||||||
##
|
##
|
||||||
## Value: Number
|
## Value: Number
|
||||||
|
|
|
@ -1094,6 +1094,11 @@ end}.
|
||||||
{datatype, [integer, ip]}
|
{datatype, [integer, ip]}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.ws.$name.standard_mqtt", "emqx.listeners", [
|
||||||
|
{default, true},
|
||||||
|
{datatype, {enum, [true, false]}}
|
||||||
|
]}.
|
||||||
|
|
||||||
{mapping, "listener.ws.$name.acceptors", "emqx.listeners", [
|
{mapping, "listener.ws.$name.acceptors", "emqx.listeners", [
|
||||||
{default, 8},
|
{default, 8},
|
||||||
{datatype, integer}
|
{datatype, integer}
|
||||||
|
@ -1195,6 +1200,11 @@ end}.
|
||||||
{datatype, [integer, ip]}
|
{datatype, [integer, ip]}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
|
{mapping, "listener.wss.$name.standard_mqtt", "emqx.listeners", [
|
||||||
|
{default, true},
|
||||||
|
{datatype, {enum, [true, false]}}
|
||||||
|
]}.
|
||||||
|
|
||||||
{mapping, "listener.wss.$name.acceptors", "emqx.listeners", [
|
{mapping, "listener.wss.$name.acceptors", "emqx.listeners", [
|
||||||
{default, 8},
|
{default, 8},
|
||||||
{datatype, integer}
|
{datatype, integer}
|
||||||
|
@ -1365,7 +1375,8 @@ end}.
|
||||||
end,
|
end,
|
||||||
|
|
||||||
LisOpts = fun(Prefix) ->
|
LisOpts = fun(Prefix) ->
|
||||||
Filter([{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
|
Filter([{standard_mqtt, cuttlefish:conf_get(Prefix ++ ".standard_mqtt", Conf, undefined)},
|
||||||
|
{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)},
|
||||||
{max_connections, cuttlefish:conf_get(Prefix ++ ".max_connections", Conf)},
|
{max_connections, cuttlefish:conf_get(Prefix ++ ".max_connections", Conf)},
|
||||||
{max_conn_rate, cuttlefish:conf_get(Prefix ++ ".max_conn_rate", Conf, undefined)},
|
{max_conn_rate, cuttlefish:conf_get(Prefix ++ ".max_conn_rate", Conf, undefined)},
|
||||||
{tune_buffer, cuttlefish:conf_get(Prefix ++ ".tune_buffer", Conf, undefined)},
|
{tune_buffer, cuttlefish:conf_get(Prefix ++ ".tune_buffer", Conf, undefined)},
|
||||||
|
|
|
@ -51,12 +51,12 @@ start_listener(Proto, ListenOn, Options) when Proto == ssl; Proto == tls ->
|
||||||
|
|
||||||
%% Start MQTT/WS listener
|
%% Start MQTT/WS listener
|
||||||
start_listener(Proto, ListenOn, Options) when Proto == http; Proto == ws ->
|
start_listener(Proto, ListenOn, Options) when Proto == http; Proto == ws ->
|
||||||
Dispatch = cowboy_router:compile([{'_', [{"/mqtt", emqx_ws_connection, Options}]}]),
|
Dispatch = cowboy_router:compile([{'_', [{subprotocol_name(Options), emqx_ws_connection, Options}]}]),
|
||||||
start_http_listener(fun cowboy:start_clear/3, 'mqtt:ws', ListenOn, ranch_opts(Options), Dispatch);
|
start_http_listener(fun cowboy:start_clear/3, 'mqtt:ws', ListenOn, ranch_opts(Options), Dispatch);
|
||||||
|
|
||||||
%% Start MQTT/WSS listener
|
%% Start MQTT/WSS listener
|
||||||
start_listener(Proto, ListenOn, Options) when Proto == https; Proto == wss ->
|
start_listener(Proto, ListenOn, Options) when Proto == https; Proto == wss ->
|
||||||
Dispatch = cowboy_router:compile([{'_', [{"/mqtt", emqx_ws_connection, Options}]}]),
|
Dispatch = cowboy_router:compile([{'_', [{subprotocol_name(Options), emqx_ws_connection, Options}]}]),
|
||||||
start_http_listener(fun cowboy:start_tls/3, 'mqtt:wss', ListenOn, ranch_opts(Options), Dispatch).
|
start_http_listener(fun cowboy:start_tls/3, 'mqtt:wss', ListenOn, ranch_opts(Options), Dispatch).
|
||||||
|
|
||||||
start_mqtt_listener(Name, ListenOn, Options) ->
|
start_mqtt_listener(Name, ListenOn, Options) ->
|
||||||
|
@ -67,6 +67,12 @@ start_mqtt_listener(Name, ListenOn, Options) ->
|
||||||
start_http_listener(Start, Name, ListenOn, RanchOpts, Dispatch) ->
|
start_http_listener(Start, Name, ListenOn, RanchOpts, Dispatch) ->
|
||||||
Start(Name, with_port(ListenOn, RanchOpts), #{env => #{dispatch => Dispatch}}).
|
Start(Name, with_port(ListenOn, RanchOpts), #{env => #{dispatch => Dispatch}}).
|
||||||
|
|
||||||
|
subprotocol_name(Options) ->
|
||||||
|
case proplists:get_value(standard_mqtt, Options, true) of
|
||||||
|
true -> "/mqtt";
|
||||||
|
false -> "/"
|
||||||
|
end.
|
||||||
|
|
||||||
ranch_opts(Options) ->
|
ranch_opts(Options) ->
|
||||||
NumAcceptors = proplists:get_value(acceptors, Options, 4),
|
NumAcceptors = proplists:get_value(acceptors, Options, 4),
|
||||||
MaxConnections = proplists:get_value(max_connections, Options, 1024),
|
MaxConnections = proplists:get_value(max_connections, Options, 1024),
|
||||||
|
|
Loading…
Reference in New Issue