@@ -54,24 +54,27 @@ mqtt_init() ->
54
54
CowboyOpts = CowboyOpts0 #{env => #{dispatch => Routes },
55
55
middlewares => [cowboy_router , rabbit_web_mqtt_middleware , cowboy_handler ],
56
56
proxy_header => get_env (proxy_protocol , false )},
57
- {TCPConf , IpStr , Port } = get_tcp_conf (),
58
-
59
- case ranch :start_listener (web_mqtt , get_env (num_tcp_acceptors , 10 ),
60
- ranch_tcp , TCPConf ,
61
- rabbit_web_mqtt_connection_sup , CowboyOpts ) of
62
- {ok , _ } -> ok ;
63
- {error , {already_started , _ }} -> ok ;
64
- {error , Err } ->
65
- rabbit_log_connection :error (
66
- " Failed to start a WebSocket (HTTP) listener. Error: ~p ,"
67
- " listener settings: ~p~n " ,
68
- [Err , TCPConf ]),
69
- throw (Err )
57
+ case get_env (tcp_config , []) of
58
+ [] ->
59
+ ok ;
60
+ TCPConf0 ->
61
+ {TCPConf , IpStr , Port } = get_tcp_conf (TCPConf0 ),
62
+ case ranch :start_listener (web_mqtt , get_env (num_tcp_acceptors , 10 ),
63
+ ranch_tcp , TCPConf ,
64
+ rabbit_web_mqtt_connection_sup , CowboyOpts ) of
65
+ {ok , _ } -> ok ;
66
+ {error , {already_started , _ }} -> ok ;
67
+ {error , ErrTCP } ->
68
+ rabbit_log_connection :error (
69
+ " Failed to start a WebSocket (HTTP) listener. Error: ~p ,"
70
+ " listener settings: ~p~n " ,
71
+ [ErrTCP , TCPConf ]),
72
+ throw (ErrTCP )
73
+ end ,
74
+ listener_started ('http/web-mqtt' , TCPConf ),
75
+ rabbit_log :info (" rabbit_web_mqtt: listening for HTTP connections on ~s :~w~n " ,
76
+ [IpStr , Port ])
70
77
end ,
71
- listener_started ('http/web-mqtt' , TCPConf ),
72
- rabbit_log :info (" rabbit_web_mqtt: listening for HTTP connections on ~s :~w~n " ,
73
- [IpStr , Port ]),
74
-
75
78
case get_env (ssl_config , []) of
76
79
[] ->
77
80
ok ;
@@ -81,6 +84,18 @@ mqtt_init() ->
81
84
{ok , _ } = ranch :start_listener (web_mqtt_secure , get_env (num_ssl_acceptors , 10 ),
82
85
ranch_ssl , TLSConf ,
83
86
rabbit_web_mqtt_connection_sup , CowboyOpts ),
87
+ case ranch :start_listener (web_mqtt_secure , get_env (num_ssl_acceptors , 10 ),
88
+ ranch_ssl , TLSConf ,
89
+ rabbit_web_mqtt_connection_sup , CowboyOpts ) of
90
+ {ok , _ } -> ok ;
91
+ {error , {already_started , _ }} -> ok ;
92
+ {error , ErrTLS } ->
93
+ rabbit_log_connection :error (
94
+ " Failed to start a TLS WebSocket (HTTPS) listener. Error: ~p ,"
95
+ " listener settings: ~p~n " ,
96
+ [ErrTLS , TLSConf ]),
97
+ throw (ErrTLS )
98
+ end ,
84
99
listener_started ('https/web-mqtt' , TLSConf ),
85
100
rabbit_log :info (" rabbit_web_mqtt: listening for HTTPS connections on ~s :~w~n " ,
86
101
[TLSIpStr , TLSPort ])
@@ -95,13 +110,13 @@ listener_started(Protocol, Listener) ->
95
110
<- rabbit_networking :tcp_listener_addresses (Port )],
96
111
ok .
97
112
98
- get_tcp_conf () ->
99
- TCPConf0 = [{connection_type , supervisor }|get_env ( tcp_config , []) ],
100
- TCPConf1 = case proplists :get_value (port , TCPConf0 ) of
101
- undefined -> [{port , 15675 }|TCPConf0 ];
102
- _ -> TCPConf0
113
+ get_tcp_conf (TCPConf0 ) ->
114
+ TCPConf1 = [{connection_type , supervisor }|TCPConf0 ],
115
+ TCPConf2 = case proplists :get_value (port , TCPConf1 ) of
116
+ undefined -> [{port , 15675 }|TCPConf1 ];
117
+ _ -> TCPConf1
103
118
end ,
104
- get_ip_port (TCPConf1 ).
119
+ get_ip_port (TCPConf2 ).
105
120
106
121
get_tls_conf (TLSConf0 ) ->
107
122
TLSConf1 = [{connection_type , supervisor }|TLSConf0 ],
0 commit comments