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