mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-11-30 03:07:40 +08:00
feat: add mqtt childspec
This commit is contained in:
parent
44ad03335a
commit
47e56a4727
@ -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)}.
|
||||
|
||||
|
||||
%% 通道消息处理,注意:进程池调用
|
||||
|
@ -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}
|
||||
|
@ -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]) ->
|
||||
|
Loading…
Reference in New Issue
Block a user