@@ -127,6 +127,24 @@ the message is processed, but other situations, like the use of the
127
127
[code noAck] flag by a message consumer, can also make the guarantees
128
128
provided by "mandatory" and "immediate" conditional.
129
129
130
+ Alternatively, one could use Publisher Confirms. Setting an channel
131
+ into [i confirm mode] by calling [code IModel.ConfirmSelect] causes
132
+ the broker to send a [code Basic.Ack] after each message is processed
133
+ by delivering to a ready consumer or by persisting to disk.
134
+
135
+ Once a successfully processed message has been confirmed via the [code
136
+ IModel.BasicAcks] event handler, the broker has assumed responsibility
137
+ for the message and the client may consider the message [i handled].
138
+
139
+ Note that the broker may also [i negatively acknowledge] a message by
140
+ sending back a [code Basic.Nack]. In this case, if a message is
141
+ rejected via the [code IModel.BasicNacks] event handler, the client
142
+ should assume that the message was lost or otherwise undeliverable.
143
+
144
+ Note that unroutable messages - mandatory or immediate messages
145
+ published to non-existing queues or queues without consumers - are
146
+ both [code Basic.Return'ed] and [code Basic.Ack'ed].
147
+
130
148
**** Receiving replies
131
149
132
150
AMQP's Basic-class content header ([code IBasicProperties]) contains a
@@ -471,9 +489,10 @@ two AMQP clients involved: the publisher, and the consumer.
471
489
Responsibility can be partially transferred to the broker by using
472
490
durable queues, durable exchanges, persistent-mode delivered messages
473
491
(with [code DeliveryMode] set equal to 2), and [code Tx]-class
474
- transactions.
492
+ transactions or Publisher Confirms .
475
493
476
- To transfer responsibility for delivery of a message to a broker
494
+ To transfer responsibility for delivery of a message to a broker using
495
+ [code Tx]
477
496
478
497
- ensure (ahead of time) that the target queue exists and is durable,
479
498
@@ -493,6 +512,33 @@ A commit is not required after every message: batching of publications
493
512
may be done, depending on the precise delivery guarantees the
494
513
publishing application requires.
495
514
515
+ To transfer responsibility for delivery of a message to a broker using
516
+ Publisher Confirms
517
+
518
+ - ensure (ahead of time) that the target queue is durable,
519
+
520
+ - select Confirm mode using [code IModel.ConfirmSelect],
521
+
522
+ - publish the message with "mandatory" flag set and [code
523
+ DeliveryMode] set equal to 2,
524
+
525
+ - listen for acknowledgements and negative acknowledgments by setting
526
+ the [code IModel.BasicAcks] and [code BasicNacks] event handlers.
527
+
528
+ Once a broker acknowledges a message via the [code BasicAcks] handler,
529
+ it has taken responsibility for keeping the message on disk and on the
530
+ target queue until some other application retrieves and acknowledges
531
+ the message.
532
+
533
+ If a broker rejects a message via the [code BasicNacks] handler, the
534
+ publisher may assume that the message was lost or otherwise
535
+ undeliverable.
536
+
537
+ Note that for unroutable messages are not considered failures and are
538
+ both [code Basic.Return'ed] and [code Basic.Ack'ed]. So, if the
539
+ "mandatory" or "immediate" are used, the client must also listen for
540
+ returns by setting the [code IModel.BasicReturn] handler.
541
+
496
542
Responsibility can also be placed with an external database, even
497
543
further along the chain - see the section on interaction with external
498
544
resources below.
@@ -544,6 +590,13 @@ consuming side before some kind of failure occurs. In these
544
590
situations, there will be partial duplication of a transaction: some
545
591
of the messages in the transaction will be delivered more than once.
546
592
593
+ Alternatively, rather than implement the round-trip logic manually, a
594
+ client may use Publisher Confirms. By enabling Confirm mode on a
595
+ channel, a client is requesting that the broker acknowledge or
596
+ negatively acknowledge all messages sent on the channel from that
597
+ point on. See the instructions from Responsibility Transfer on how to
598
+ use confirms.
599
+
547
600
Deciding on a message-resend policy can be difficult. Some simple
548
601
resend strategies are:
549
602
0 commit comments