feat: add mqtt childspec

This commit is contained in:
U-JOHNLIU\jonhl 2022-03-21 20:06:56 +08:00
parent 44ad03335a
commit 47e56a4727
3 changed files with 8 additions and 6 deletions

View File

@ -88,7 +88,8 @@ init(?TYPE, ChannelId, ChannelArgs) ->
id = ChannelId,
env = maps:without([<<"port">>,<<"path">>,<<"product">>,<<"behaviour">>], ChannelArgs)
},
{ok, State, dgiot_http_worker:childSpec(?TYPE, ChannelId, ChannelArgs)}.
Name = dgiot_channelx:get_name(?TYPE, ChannelId),
{ok, State, dgiot_http_worker:childSpec(Name, ChannelId, ChannelArgs)}.
%% ,

View File

@ -25,12 +25,11 @@
-export([childSpec/3,
init/2]).
childSpec(Type, ChannelId, #{<<"port">> := Port} = ChannelArgs) ->
childSpec(Name, ChannelId, #{<<"port">> := Port} = ChannelArgs) ->
State = #state{
id = ChannelId,
env = maps:without([<<"port">>,<<"path">>,<<"product">>,<<"behaviour">>], ChannelArgs)
},
Name = dgiot_channelx:get_name(Type, ChannelId),
Opts = [
{ip, {0, 0, 0, 0}},
{port, Port}

View File

@ -21,17 +21,19 @@
-export([childSpec/3, init/1, handle_info/2, handle_cast/2, handle_call/3, terminate/2, code_change/3]).
childSpec(ChannelId, State, ChannelArgs) ->
-define(CHILD(I, Type, Args), {I, {I, start_link, Args}, permanent, 5000, Type, [I]}).
childSpec(ClientID, State, ChannelArgs) ->
Options = [
{host, binary_to_list(maps:get(<<"address">>, ChannelArgs))},
{port, maps:get(<<"port">>, ChannelArgs)},
{clientid, ChannelId},
{clientid, ClientID},
{ssl, maps:get(<<"ssl">>, ChannelArgs, false)},
{username, binary_to_list(maps:get(<<"username">>, ChannelArgs))},
{password, binary_to_list(maps:get(<<"password">>, ChannelArgs))},
{clean_start, maps:get(<<"clean_start">>, ChannelArgs, false)}
],
[{dgiot_mqtt_client, {dgiot_mqtt_client, start_link, [?MODULE, [State], Options]}, permanent, 5000, worker, [dgiot_mqtt_client]}].
[?CHILD(dgiot_mqtt_client, worker,[?MODULE, [State], Options])].
%% mqtt client hook
init([State]) ->