373373
374374 % % Queue actions that we will process later such that we can confirm and reject
375375 % % delivery IDs in ranges to reduce the number of DISPOSITION frames sent to the client.
376- stashed_rejected = [] :: [{rejected , rabbit_amqqueue :name (), [delivery_number (),...]}],
376+ stashed_rejected = [] :: [{rejected ,
377+ rabbit_amqqueue :name (),
378+ rabbit_queue_type :reject_reason (),
379+ [delivery_number (),...]}],
377380 stashed_settled = [] :: [{settled , rabbit_amqqueue :name (), [delivery_number (),...]}],
378381 % % Classic queues that are down.
379382 stashed_down = []:: [rabbit_amqqueue :name ()],
@@ -692,7 +695,17 @@ send_delivery_state_changes(State0 = #state{cfg = #cfg{writer_pid = Writer,
692695 % % Order is important:
693696 % % 1. Process queue rejections.
694697 {RejectedIds , GrantCredits0 , State1 } = handle_stashed_rejected (State0 ),
695- send_dispositions (RejectedIds , # 'v1_0.rejected' {}, Writer , ChannelNum ),
698+ maps :foreach (
699+ fun ({QNameBin , Reason }, Ids ) ->
700+ Info = {map ,
701+ [{{symbol , <<" queue" >>}, {utf8 , QNameBin }},
702+ {{symbol , <<" reason" >>}, {symbol , reject_reason_to_binary (Reason )}}]},
703+ Rej = # 'v1_0.rejected' {
704+ error = # 'v1_0.error' {
705+ condition = ? V_1_0_AMQP_ERROR_PRECONDITION_FAILED ,
706+ info = Info }},
707+ send_dispositions (Ids , Rej , Writer , ChannelNum )
708+ end , RejectedIds ),
696709 % % 2. Process queue confirmations.
697710 {AcceptedIds0 , GrantCredits1 , State2 } = handle_stashed_settled (GrantCredits0 , State1 ),
698711 % % 3. Process unavailable classic queues.
@@ -716,22 +729,28 @@ send_delivery_state_changes(State0 = #state{cfg = #cfg{writer_pid = Writer,
716729 State .
717730
718731handle_stashed_rejected (# state {stashed_rejected = []} = State ) ->
719- {[] , #{}, State };
732+ {#{} , #{}, State };
720733handle_stashed_rejected (# state {cfg = # cfg {max_link_credit = MaxLinkCredit },
721734 stashed_rejected = Actions ,
722735 incoming_links = Links } = State0 ) ->
723736 {Ids , GrantCredits , Ls } =
724737 lists :foldl (
725- fun ({rejected , _QName , Correlations }, Accum ) ->
738+ fun ({rejected , # resource { name = QNameBin }, Reason , Correlations }, Accum ) ->
726739 lists :foldl (
727740 fun ({HandleInt , DeliveryId }, {Ids0 , GrantCreds0 , Links0 } = Acc ) ->
728741 case Links0 of
729742 #{HandleInt := Link0 = # incoming_link {incoming_unconfirmed_map = U0 }} ->
730743 case maps :take (DeliveryId , U0 ) of
731744 {{_ , Settled , _ }, U } ->
732745 Ids1 = case Settled of
733- true -> Ids0 ;
734- false -> [DeliveryId | Ids0 ]
746+ true ->
747+ Ids0 ;
748+ false ->
749+ maps :update_with (
750+ {QNameBin , Reason },
751+ fun (L ) -> [DeliveryId | L ] end ,
752+ [DeliveryId ],
753+ Ids0 )
735754 end ,
736755 Link1 = Link0 # incoming_link {incoming_unconfirmed_map = U },
737756 {Link , GrantCreds } = maybe_grant_link_credit (
@@ -745,7 +764,7 @@ handle_stashed_rejected(#state{cfg = #cfg{max_link_credit = MaxLinkCredit},
745764 Acc
746765 end
747766 end , Accum , Correlations )
748- end , {[] , #{}, Links }, Actions ),
767+ end , {#{} , #{}, Links }, Actions ),
749768
750769 State = State0 # state {stashed_rejected = [],
751770 incoming_links = Ls },
@@ -2116,7 +2135,7 @@ handle_queue_actions(Actions, State) ->
21162135 lists :foldl (
21172136 fun ({settled , _QName , _DelIds } = Action , # state {stashed_settled = As } = S ) ->
21182137 S # state {stashed_settled = [Action | As ]};
2119- ({rejected , _QName , _DelIds } = Action , # state {stashed_rejected = As } = S ) ->
2138+ ({rejected , _QName , _Reason , _DelIds } = Action , # state {stashed_rejected = As } = S ) ->
21202139 S # state {stashed_rejected = [Action | As ]};
21212140 ({deliver , CTag , AckRequired , Msgs }, S0 ) ->
21222141 lists :foldl (fun (Msg , S ) ->
@@ -2584,6 +2603,11 @@ rejected(DeliveryId, Error) ->
25842603 settled = true ,
25852604 state = # 'v1_0.rejected' {error = Error }}.
25862605
2606+ reject_reason_to_binary (maxlen ) ->
2607+ <<" maxlen" >>;
2608+ reject_reason_to_binary (down ) ->
2609+ <<" unavailable" >>.
2610+
25872611maybe_grant_link_credit (Credit , MaxLinkCredit , DeliveryCount , NumUnconfirmed , Handle ) ->
25882612 case grant_link_credit (Credit , MaxLinkCredit , NumUnconfirmed ) of
25892613 true ->
0 commit comments