parent
c4403e886d
commit
237d3c0543
|
@ -1,28 +1,28 @@
|
||||||
|
|
||||||
auto_subscribe {
|
auto_subscribe {
|
||||||
topics = [
|
topics = [
|
||||||
# {
|
## {
|
||||||
# topic = "/c/${clientid}",
|
## topic = "/c/${clientid}"
|
||||||
# qos = 0
|
## qos = 0
|
||||||
# rh = 0
|
## rh = 0
|
||||||
# rap = 0
|
## rap = 0
|
||||||
# nl = 0
|
## nl = 0
|
||||||
# }
|
## },
|
||||||
# {
|
## {
|
||||||
# topic = "/u/${username}",
|
## topic = "/u/${username}"
|
||||||
# },
|
## },
|
||||||
# {
|
## {
|
||||||
# topic = "/h/${host}",
|
## topic = "/h/${host}"
|
||||||
# qos = 2
|
## qos = 2
|
||||||
# },
|
## },
|
||||||
# {
|
## {
|
||||||
# topic = "/p/${port}",
|
## topic = "/p/${port}"
|
||||||
# },
|
## },
|
||||||
# {
|
## {
|
||||||
# topic = "/topic/abc",
|
## topic = "/topic/abc"
|
||||||
# },
|
## },
|
||||||
# {
|
## {
|
||||||
# topic = "/client/${clientid}/username/${username}/host/${host}/port/${port}",
|
## topic = "/client/${clientid}/username/${username}/host/${host}/port/${port}"
|
||||||
# }
|
## }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ max_limit() ->
|
||||||
?MAX_AUTO_SUBSCRIBE.
|
?MAX_AUTO_SUBSCRIBE.
|
||||||
|
|
||||||
list() ->
|
list() ->
|
||||||
emqx:get_config([auto_subscribe, topics], []).
|
format(emqx:get_config([auto_subscribe, topics], [])).
|
||||||
|
|
||||||
update(Topics) ->
|
update(Topics) ->
|
||||||
update_(Topics).
|
update_(Topics).
|
||||||
|
@ -68,6 +68,17 @@ on_client_connected(_, _, _) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% internal
|
%% internal
|
||||||
|
|
||||||
|
format(Rules) when is_list(Rules) ->
|
||||||
|
[format(Rule) || Rule <- Rules];
|
||||||
|
format(Rule = #{topic := Topic}) when is_map(Rule) ->
|
||||||
|
#{
|
||||||
|
topic => Topic,
|
||||||
|
qos => maps:get(qos, Rule, 0),
|
||||||
|
rh => maps:get(rh, Rule, 0),
|
||||||
|
rap => maps:get(rap, Rule, 0),
|
||||||
|
nl => maps:get(nl, Rule, 0)
|
||||||
|
}.
|
||||||
|
|
||||||
update_(Topics) when length(Topics) =< ?MAX_AUTO_SUBSCRIBE ->
|
update_(Topics) when length(Topics) =< ?MAX_AUTO_SUBSCRIBE ->
|
||||||
{ok, _} = emqx:update_config([auto_subscribe, topics], Topics),
|
{ok, _} = emqx:update_config([auto_subscribe, topics], Topics),
|
||||||
update_hook();
|
update_hook();
|
||||||
|
|
Loading…
Reference in New Issue