Fix the massages order when batch dispatching

This commit is contained in:
tradingtrace 2019-06-23 11:20:22 +08:00 committed by turtleDeng
parent 22f7280d8e
commit 0b116bc208
1 changed files with 4 additions and 1 deletions

View File

@ -798,7 +798,7 @@ handle_dispatch(Msgs, State = #state{inflight = Inflight,
subscriptions = SubMap}) -> subscriptions = SubMap}) ->
SessProps = #{client_id => ClientId, username => Username}, SessProps = #{client_id => ClientId, username => Username},
%% Drain the mailbox and batch deliver %% Drain the mailbox and batch deliver
Msgs1 = drain_m(batch_n(Inflight), Msgs), Msgs1 = Msgs ++ drain_m(batch_n(Inflight)),
%% Ack the messages for shared subscription %% Ack the messages for shared subscription
Msgs2 = maybe_ack_shared(Msgs1, State), Msgs2 = maybe_ack_shared(Msgs1, State),
%% Process suboptions %% Process suboptions
@ -821,6 +821,9 @@ batch_n(Inflight) ->
Sz -> Sz - emqx_inflight:size(Inflight) Sz -> Sz - emqx_inflight:size(Inflight)
end. end.
drain_m(Cnt) ->
drain_m(Cnt, []).
drain_m(Cnt, Msgs) when Cnt =< 0 -> drain_m(Cnt, Msgs) when Cnt =< 0 ->
lists:reverse(Msgs); lists:reverse(Msgs);
drain_m(Cnt, Msgs) -> drain_m(Cnt, Msgs) ->