13
13
-include_lib (" amqp10_common/include/amqp10_types.hrl" ).
14
14
-include (" rabbit_amqp1_0.hrl" ).
15
15
16
+ -define (PROTOCOL , amqp10 ).
16
17
-define (HIBERNATE_AFTER , 6_000 ).
17
18
-define (CREDIT_REPLY_TIMEOUT , 30_000 ).
18
19
-define (UINT_OUTGOING_WINDOW , {uint , ? UINT_MAX }).
89
90
-record (outgoing_link , {
90
91
% % Although the source address of a link might be an exchange name and binding key
91
92
% % or a topic filter, an outgoing link will always consume from a queue.
92
- queue :: rabbit_misc :resource_name (),
93
+ queue_name :: rabbit_misc :resource_name (),
94
+ queue_type :: rabbit_queue_type :queue_type (),
93
95
send_settled :: boolean (),
94
96
max_message_size :: unlimited | pos_integer (),
95
97
% % When credit API v1 is used, our session process holds the delivery-count
@@ -435,6 +437,7 @@ send_delivery_state_changes(State0 = #state{cfg = #cfg{writer_pid = Writer,
435
437
send_dispositions (ReleasedIds , # 'v1_0.released' {}, Writer , ChannelNum ),
436
438
AcceptedIds = AcceptedIds1 ++ AcceptedIds0 ,
437
439
send_dispositions (AcceptedIds , # 'v1_0.accepted' {}, Writer , ChannelNum ),
440
+ rabbit_global_counters :messages_confirmed (? PROTOCOL , length (AcceptedIds )),
438
441
% % Send DETACH frames after DISPOSITION frames such that
439
442
% % clients can handle DISPOSITIONs before closing their links.
440
443
lists :foreach (fun (Frame ) ->
@@ -624,7 +627,7 @@ destroy_incoming_link(Handle, #incoming_link{queue = QNameBin}, QNameBin, {Frame
624
627
destroy_incoming_link (_ , _ , _ , Acc ) ->
625
628
Acc .
626
629
627
- destroy_outgoing_link (Handle , # outgoing_link {queue = QNameBin }, QNameBin , {Frames , Unsettled0 , Links }) ->
630
+ destroy_outgoing_link (Handle , # outgoing_link {queue_name = QNameBin }, QNameBin , {Frames , Unsettled0 , Links }) ->
628
631
{Unsettled , _RemovedMsgIds } = remove_link_from_outgoing_unsettled_map (Handle , Unsettled0 ),
629
632
{[detach (Handle , ? V_1_0_AMQP_ERROR_RESOURCE_DELETED ) | Frames ],
630
633
Unsettled ,
@@ -744,6 +747,7 @@ handle_control(#'v1_0.attach'{role = ?RECV_ROLE,
744
747
case rabbit_amqqueue :with (
745
748
QName ,
746
749
fun (Q ) ->
750
+ QType = amqqueue :get_type (Q ),
747
751
% % Whether credit API v1 or v2 is used is decided only here at link attachment time.
748
752
% % This decision applies to the whole life time of the link.
749
753
% % This means even when feature flag credit_api_v2 will be enabled later, this consumer will
@@ -756,7 +760,7 @@ handle_control(#'v1_0.attach'{role = ?RECV_ROLE,
756
760
% % flow control state. Hence, credit API mixed version isn't an issue for streams.
757
761
{Mode ,
758
762
DeliveryCount } = case rabbit_feature_flags :is_enabled (credit_api_v2 ) orelse
759
- amqqueue : get_type ( Q ) =:= rabbit_stream_queue of
763
+ QType =:= rabbit_stream_queue of
760
764
true ->
761
765
{{credited , ? INITIAL_DELIVERY_COUNT }, credit_api_v2 };
762
766
false ->
@@ -799,7 +803,8 @@ handle_control(#'v1_0.attach'{role = ?RECV_ROLE,
799
803
% % maximum size imposed by the link endpoint."
800
804
unlimited
801
805
end ,
802
- Link = # outgoing_link {queue = QNameBin ,
806
+ Link = # outgoing_link {queue_name = QNameBin ,
807
+ queue_type = QType ,
803
808
send_settled = SndSettled ,
804
809
max_message_size = MaxMessageSize ,
805
810
delivery_count = DeliveryCount },
@@ -914,7 +919,7 @@ handle_control(#'v1_0.detach'{handle = Handle = ?UINT(HandleInt),
914
919
% % TODO keep the state around depending on the lifetime
915
920
{QStates , Unsettled , OutgoingLinks }
916
921
= case maps :take (HandleInt , OutgoingLinks0 ) of
917
- {# outgoing_link {queue = QNameBin }, OutgoingLinks1 } ->
922
+ {# outgoing_link {queue_name = QNameBin }, OutgoingLinks1 } ->
918
923
QName = rabbit_misc :r (Vhost , queue , QNameBin ),
919
924
case rabbit_amqqueue :lookup (QName ) of
920
925
{ok , Q } ->
@@ -1041,6 +1046,7 @@ handle_control(#'v1_0.disposition'{role = ?RECV_ROLE,
1041
1046
fun ({QName , Ctag }, MsgIds , {QS0 , ActionsAcc }) ->
1042
1047
case rabbit_queue_type_settle (QName , SettleOp , Ctag , MsgIds , QS0 ) of
1043
1048
{ok , QS , Actions0 } ->
1049
+ messages_acknowledged (SettleOp , QName , QS , MsgIds ),
1044
1050
{QS , ActionsAcc ++ Actions0 };
1045
1051
{protocol_error , _ErrorType , Reason , ReasonArgs } ->
1046
1052
protocol_error (? V_1_0_AMQP_ERROR_INTERNAL_ERROR ,
@@ -1377,7 +1383,8 @@ handle_deliver(ConsumerTag, AckRequired,
1377
1383
cfg = # cfg {outgoing_max_frame_size = MaxFrameSize }}) ->
1378
1384
Handle = ctag_to_handle (ConsumerTag ),
1379
1385
case OutgoingLinks of
1380
- #{Handle := # outgoing_link {send_settled = SendSettled ,
1386
+ #{Handle := # outgoing_link {queue_type = QType ,
1387
+ send_settled = SendSettled ,
1381
1388
max_message_size = MaxMessageSize }} ->
1382
1389
% % "The delivery-tag MUST be unique amongst all deliveries that could be
1383
1390
% % considered unsettled by either end of the link." [2.6.12]
@@ -1418,6 +1425,7 @@ handle_deliver(ConsumerTag, AckRequired,
1418
1425
TLen = iolist_size (amqp10_framing :encode_bin (Transfer )),
1419
1426
encode_frames (Transfer , Sections , MaxFrameSize - TLen , [])
1420
1427
end ,
1428
+ messages_delivered (Redelivered , QType ),
1421
1429
Del = # outgoing_unsettled {
1422
1430
msg_id = MsgId ,
1423
1431
consumer_tag = ConsumerTag ,
@@ -1533,7 +1541,7 @@ incoming_link_transfer(
1533
1541
RoutingKeys = mc :get_annotation (routing_keys , Mc ),
1534
1542
RoutingKey = routing_key (RoutingKeys , XName ),
1535
1543
% Mc1 = rabbit_message_interceptor:intercept(Mc),
1536
- % rabbit_global_counters: messages_received(ProtoVer, 1 ),
1544
+ messages_received (Settled ),
1537
1545
case rabbit_exchange :lookup (XName ) of
1538
1546
{ok , Exchange } ->
1539
1547
check_write_permitted_on_topic (Exchange , User , RoutingKey ),
@@ -1551,7 +1559,6 @@ incoming_link_transfer(
1551
1559
case rabbit_queue_type :deliver (Qs , Mc , Opts , QStates0 ) of
1552
1560
{ok , QStates , Actions } ->
1553
1561
State1 = State0 # state {queue_states = QStates },
1554
- % rabbit_global_counters:messages_routed(ProtoVer, length(Qs)),
1555
1562
% % Confirms must be registered before processing actions
1556
1563
% % because actions may contain rejections of publishes.
1557
1564
{U , Reply0 } = process_routing_confirm (
@@ -1582,16 +1589,18 @@ incoming_link_transfer(
1582
1589
end .
1583
1590
1584
1591
process_routing_confirm ([], _SenderSettles = true , _ , U ) ->
1585
- % rabbit_global_counters:messages_unroutable_dropped(ProtoVer , 1),
1592
+ rabbit_global_counters :messages_unroutable_dropped (? PROTOCOL , 1 ),
1586
1593
{U , []};
1587
1594
process_routing_confirm ([], _SenderSettles = false , DeliveryId , U ) ->
1588
- % rabbit_global_counters:messages_unroutable_returned(ProtoVer , 1),
1595
+ rabbit_global_counters :messages_unroutable_returned (? PROTOCOL , 1 ),
1589
1596
Disposition = released (DeliveryId ),
1590
1597
{U , [Disposition ]};
1591
1598
process_routing_confirm ([_ |_ ] = Qs , SenderSettles , DeliveryId , U0 ) ->
1592
1599
QNames = rabbit_amqqueue :queue_names (Qs ),
1593
1600
false = maps :is_key (DeliveryId , U0 ),
1594
- U = U0 #{DeliveryId => {maps :from_keys (QNames , ok ), SenderSettles , false }},
1601
+ Map = maps :from_keys (QNames , ok ),
1602
+ U = U0 #{DeliveryId => {Map , SenderSettles , false }},
1603
+ rabbit_global_counters :messages_routed (? PROTOCOL , map_size (Map )),
1595
1604
{U , []}.
1596
1605
1597
1606
released (DeliveryId ) ->
@@ -1656,7 +1665,7 @@ ensure_target(#'v1_0.target'{address = Address,
1656
1665
end .
1657
1666
1658
1667
handle_outgoing_link_flow_control (
1659
- # outgoing_link {queue = QNameBin ,
1668
+ # outgoing_link {queue_name = QNameBin ,
1660
1669
delivery_count = MaybeDeliveryCountSnd },
1661
1670
# 'v1_0.flow' {handle = ? UINT (HandleInt ),
1662
1671
delivery_count = MaybeDeliveryCountRcv ,
@@ -2065,6 +2074,30 @@ routing_key(undefined, XName) ->
2065
2074
routing_key ([RoutingKey ], _XName ) ->
2066
2075
RoutingKey .
2067
2076
2077
+ messages_received (Settled ) ->
2078
+ rabbit_global_counters :messages_received (? PROTOCOL , 1 ),
2079
+ case Settled of
2080
+ true -> ok ;
2081
+ false -> rabbit_global_counters :messages_received_confirm (? PROTOCOL , 1 )
2082
+ end .
2083
+
2084
+ messages_delivered (Redelivered , QueueType ) ->
2085
+ rabbit_global_counters :messages_delivered (? PROTOCOL , QueueType , 1 ),
2086
+ case Redelivered of
2087
+ true -> rabbit_global_counters :messages_redelivered (? PROTOCOL , QueueType , 1 );
2088
+ false -> ok
2089
+ end .
2090
+
2091
+ messages_acknowledged (complete , QName , QS , MsgIds ) ->
2092
+ case rabbit_queue_type :module (QName , QS ) of
2093
+ {ok , QType } ->
2094
+ rabbit_global_counters :messages_acknowledged (? PROTOCOL , QType , length (MsgIds ));
2095
+ _ ->
2096
+ ok
2097
+ end ;
2098
+ messages_acknowledged (_ , _ , _ , _ ) ->
2099
+ ok .
2100
+
2068
2101
check_internal_exchange (# exchange {internal = true ,
2069
2102
name = XName }) ->
2070
2103
protocol_error (? V_1_0_AMQP_ERROR_UNAUTHORIZED_ACCESS ,
0 commit comments