From 540484e6034ff3daeeb04132eab123d09eb33f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E5=AD=90=E5=8D=9A?= <349832309@qq.com> Date: Tue, 23 Oct 2018 17:27:46 +0800 Subject: [PATCH] Send and cancel will message by apis rather than hook --- src/emqx_protocol.erl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/emqx_protocol.erl b/src/emqx_protocol.erl index 7dd0b37e8..32ecd7137 100644 --- a/src/emqx_protocol.erl +++ b/src/emqx_protocol.erl @@ -638,6 +638,9 @@ try_open_session(PState = #pstate{zone = Zone, case emqx_sm:open_session(SessAttrs1) of {ok, SPid} -> {ok, SPid, false}; + {ok, SPid, true} -> + emqx_delayed_publish:cancel_publish(ClientId), + {ok, SPid, true}; Other -> Other end. @@ -838,11 +841,9 @@ shutdown(Reason, PState = #pstate{connected = true, send_willmsg(undefined, _ClientId) -> ignore; -send_willmsg(WillMsg = #message{topic = Topic, - headers = #{'Will-Delay-Interval' := Interval} = Headers}, ClientId) +send_willmsg(WillMsg = #message{headers = #{'Will-Delay-Interval' := Interval}}, ClientId) when is_integer(Interval), Interval > 0 -> - SendAfter = integer_to_binary(Interval), - emqx_broker:publish(WillMsg#message{topic = emqx_topic:join([<<"$will">>, SendAfter, Topic]), headers = Headers#{client_id => ClientId}}); + emqx_delayed_publish:delay_publish(WillMsg, ClientId); send_willmsg(WillMsg, _ClientId) -> emqx_broker:publish(WillMsg).