Send and cancel will message by apis rather than hook

This commit is contained in:
周子博 2018-10-23 17:27:46 +08:00
parent 55a12c1ab4
commit 540484e603
1 changed files with 5 additions and 4 deletions

View File

@ -638,6 +638,9 @@ try_open_session(PState = #pstate{zone = Zone,
case emqx_sm:open_session(SessAttrs1) of case emqx_sm:open_session(SessAttrs1) of
{ok, SPid} -> {ok, SPid} ->
{ok, SPid, false}; {ok, SPid, false};
{ok, SPid, true} ->
emqx_delayed_publish:cancel_publish(ClientId),
{ok, SPid, true};
Other -> Other Other -> Other
end. end.
@ -838,11 +841,9 @@ shutdown(Reason, PState = #pstate{connected = true,
send_willmsg(undefined, _ClientId) -> send_willmsg(undefined, _ClientId) ->
ignore; ignore;
send_willmsg(WillMsg = #message{topic = Topic, send_willmsg(WillMsg = #message{headers = #{'Will-Delay-Interval' := Interval}}, ClientId)
headers = #{'Will-Delay-Interval' := Interval} = Headers}, ClientId)
when is_integer(Interval), Interval > 0 -> when is_integer(Interval), Interval > 0 ->
SendAfter = integer_to_binary(Interval), emqx_delayed_publish:delay_publish(WillMsg, ClientId);
emqx_broker:publish(WillMsg#message{topic = emqx_topic:join([<<"$will">>, SendAfter, Topic]), headers = Headers#{client_id => ClientId}});
send_willmsg(WillMsg, _ClientId) -> send_willmsg(WillMsg, _ClientId) ->
emqx_broker:publish(WillMsg). emqx_broker:publish(WillMsg).