This commit is contained in:
anlicheng 2025-05-08 12:54:23 +08:00
parent d1e51d635d
commit c24007efc3

View File

@ -17,6 +17,8 @@ start(_StartType, _StartArgs) ->
%% mnesia数据库
start_mnesia(),
start_http_server(),
start_tcp_server(),
iot_sup:start_link().
@ -26,6 +28,33 @@ stop(_State) ->
%% internal functions
%% http服务
start_http_server() ->
{ok, Props} = application:get_env(iot, http_server),
Acceptors = proplists:get_value(acceptors, Props, 50),
MaxConnections = proplists:get_value(max_connections, Props, 10240),
Backlog = proplists:get_value(backlog, Props, 1024),
Port = proplists:get_value(port, Props),
Dispatcher = cowboy_router:compile([
{'_', [
{"/host/[...]", http_protocol, [host_handler]},
{"/device/[...]", http_protocol, [device_handler]},
{"/service/[...]", http_protocol, [service_handler]}
]}
]),
TransOpts = [
{port, Port},
{num_acceptors, Acceptors},
{backlog, Backlog},
{max_connections, MaxConnections}
],
{ok, Pid} = cowboy:start_clear(http_listener, TransOpts, #{env => #{dispatch => Dispatcher}}),
lager:debug("[iot_app] the http server start at: ~p, pid is: ~p", [Port, Pid]).
%% tcp服务
start_tcp_server() ->
{ok, Props} = application:get_env(iot, tcp_server),