refactor(config): change mqtt.session_expiry_interval to ms

This commit is contained in:
Shawn 2021-07-23 14:11:32 +08:00
parent 684e46c45d
commit 0704cbc986
6 changed files with 19 additions and 16 deletions

View File

@ -1118,7 +1118,7 @@ interval(retry_timer, #channel{session = Session}) ->
interval(await_timer, #channel{session = Session}) -> interval(await_timer, #channel{session = Session}) ->
emqx_session:info(await_rel_timeout, Session); emqx_session:info(await_rel_timeout, Session);
interval(expire_timer, #channel{conninfo = ConnInfo}) -> interval(expire_timer, #channel{conninfo = ConnInfo}) ->
timer:seconds(maps:get(expiry_interval, ConnInfo)); maps:get(expiry_interval, ConnInfo);
interval(will_timer, #channel{will_msg = WillMsg}) -> interval(will_timer, #channel{will_msg = WillMsg}) ->
timer:seconds(will_delay_interval(WillMsg)). timer:seconds(will_delay_interval(WillMsg)).
@ -1176,7 +1176,7 @@ enrich_conninfo(ConnPkt = #mqtt_packet_connect{
%% If the Session Expiry Interval is absent the value 0 is used. %% If the Session Expiry Interval is absent the value 0 is used.
expiry_interval(_, #mqtt_packet_connect{proto_ver = ?MQTT_PROTO_V5, expiry_interval(_, #mqtt_packet_connect{proto_ver = ?MQTT_PROTO_V5,
properties = ConnProps}) -> properties = ConnProps}) ->
emqx_mqtt_props:get('Session-Expiry-Interval', ConnProps, 0); timer:seconds(emqx_mqtt_props:get('Session-Expiry-Interval', ConnProps, 0));
expiry_interval(Zone, #mqtt_packet_connect{clean_start = false}) -> expiry_interval(Zone, #mqtt_packet_connect{clean_start = false}) ->
get_mqtt_conf(Zone, session_expiry_interval); get_mqtt_conf(Zone, session_expiry_interval);
expiry_interval(_, #mqtt_packet_connect{clean_start = true}) -> expiry_interval(_, #mqtt_packet_connect{clean_start = true}) ->
@ -1615,7 +1615,7 @@ maybe_shutdown(Reason, Channel = #channel{conninfo = ConnInfo}) ->
case maps:get(expiry_interval, ConnInfo) of case maps:get(expiry_interval, ConnInfo) of
?UINT_MAX -> {ok, Channel}; ?UINT_MAX -> {ok, Channel};
I when I > 0 -> I when I > 0 ->
{ok, ensure_timer(expire_timer, timer:seconds(I), Channel)}; {ok, ensure_timer(expire_timer, I, Channel)};
_ -> shutdown(Reason, Channel) _ -> shutdown(Reason, Channel)
end. end.

View File

@ -291,7 +291,7 @@ fields("mqtt") ->
, {"retry_interval", t(duration(), undefined, "30s")} , {"retry_interval", t(duration(), undefined, "30s")}
, {"max_awaiting_rel", maybe_infinity(integer(), 100)} , {"max_awaiting_rel", maybe_infinity(integer(), 100)}
, {"await_rel_timeout", t(duration(), undefined, "300s")} , {"await_rel_timeout", t(duration(), undefined, "300s")}
, {"session_expiry_interval", t(duration_s(), undefined, "2h")} , {"session_expiry_interval", t(duration(), undefined, "2h")}
, {"max_mqueue_len", maybe_infinity(range(0, inf), 1000)} , {"max_mqueue_len", maybe_infinity(range(0, inf), 1000)}
, {"mqueue_priorities", maybe_disabled(map())} , {"mqueue_priorities", maybe_disabled(map())}
, {"mqueue_default_priority", t(union(highest, lowest), undefined, lowest)} , {"mqueue_default_priority", t(union(highest, lowest), undefined, lowest)}

View File

@ -51,7 +51,7 @@ mqtt_conf() ->
retain_available => true, retain_available => true,
retry_interval => 30000, retry_interval => 30000,
server_keepalive => disabled, server_keepalive => disabled,
session_expiry_interval => 7200, session_expiry_interval => 7200000,
shared_subscription => true, shared_subscription => true,
strict_mode => false, strict_mode => false,
upgrade_qos => false, upgrade_qos => false,

View File

@ -590,18 +590,21 @@ print({client, {ClientId, ChanPid}}) ->
InfoKeys = [clientid, username, peername, InfoKeys = [clientid, username, peername,
clean_start, keepalive, expiry_interval, clean_start, keepalive, expiry_interval,
subscriptions_cnt, inflight_cnt, awaiting_rel_cnt, send_msg, mqueue_len, mqueue_dropped, subscriptions_cnt, inflight_cnt, awaiting_rel_cnt, send_msg, mqueue_len, mqueue_dropped,
connected, created_at, connected_at] ++ case maps:is_key(disconnected_at, Info) of connected, created_at, connected_at] ++
true -> [disconnected_at]; case maps:is_key(disconnected_at, Info) of
false -> [] true -> [disconnected_at];
end, false -> []
end,
Info1 = Info#{expiry_interval => maps:get(expiry_interval, Info) div 1000},
emqx_ctl:print("Client(~s, username=~s, peername=~s, " emqx_ctl:print("Client(~s, username=~s, peername=~s, "
"clean_start=~s, keepalive=~w, session_expiry_interval=~w, " "clean_start=~s, keepalive=~w, session_expiry_interval=~w, "
"subscriptions=~w, inflight=~w, awaiting_rel=~w, delivered_msgs=~w, enqueued_msgs=~w, dropped_msgs=~w, " "subscriptions=~w, inflight=~w, awaiting_rel=~w, delivered_msgs=~w, enqueued_msgs=~w, dropped_msgs=~w, "
"connected=~s, created_at=~w, connected_at=~w" ++ case maps:is_key(disconnected_at, Info) of "connected=~s, created_at=~w, connected_at=~w" ++
true -> ", disconnected_at=~w)~n"; case maps:is_key(disconnected_at, Info1) of
false -> ")~n" true -> ", disconnected_at=~w)~n";
end, false -> ")~n"
[format(K, maps:get(K, Info)) || K <- InfoKeys]); end,
[format(K, maps:get(K, Info1)) || K <- InfoKeys]);
print({emqx_route, #route{topic = Topic, dest = {_, Node}}}) -> print({emqx_route, #route{topic = Topic, dest = {_, Node}}}) ->
emqx_ctl:print("~s -> ~s~n", [Topic, Node]); emqx_ctl:print("~s -> ~s~n", [Topic, Node]);

View File

@ -102,7 +102,7 @@ connected_presence(#{peerhost := PeerHost,
keepalive => Keepalive, keepalive => Keepalive,
connack => 0, %% Deprecated? connack => 0, %% Deprecated?
clean_start => CleanStart, clean_start => CleanStart,
expiry_interval => ExpiryInterval, expiry_interval => ExpiryInterval div 1000,
connected_at => ConnectedAt, connected_at => ConnectedAt,
ts => erlang:system_time(millisecond) ts => erlang:system_time(millisecond)
}. }.

View File

@ -182,7 +182,7 @@ eventmsg_connected(_ClientInfo = #{
keepalive => Keepalive, keepalive => Keepalive,
clean_start => CleanStart, clean_start => CleanStart,
receive_maximum => RcvMax, receive_maximum => RcvMax,
expiry_interval => ExpiryInterval, expiry_interval => ExpiryInterval div 1000,
is_bridge => IsBridge, is_bridge => IsBridge,
conn_props => printable_maps(ConnProps), conn_props => printable_maps(ConnProps),
connected_at => ConnectedAt connected_at => ConnectedAt