@@ -120,13 +120,30 @@ transactions are active is underspecified in both versions 0-8 and 0-9
120
120
of the AMQP specification, and different server implementations behave
121
121
in different ways.
122
122
123
- Finally , the fact that a message was flagged "mandatory", and
123
+ Additionally , the fact that a message was flagged "mandatory", and
124
124
successfully enqueued on one or more queues, is no guarantee of its
125
125
eventual receipt: most trivially, the queue could be deleted before
126
126
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 a 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
143
+ undeliverable. Also, note that unroutable messages - mandatory or
144
+ immediate messages published to non-existing queues or queues without
145
+ consumers - are both [code Basic.Return'ed] and [code Basic.Ack'ed].
146
+
130
147
**** Receiving replies
131
148
132
149
AMQP's Basic-class content header ([code IBasicProperties]) contains a
@@ -471,9 +488,10 @@ two AMQP clients involved: the publisher, and the consumer.
471
488
Responsibility can be partially transferred to the broker by using
472
489
durable queues, durable exchanges, persistent-mode delivered messages
473
490
(with [code DeliveryMode] set equal to 2), and [code Tx]-class
474
- transactions.
491
+ transactions or Publisher Confirms .
475
492
476
- To transfer responsibility for delivery of a message to a broker
493
+ To transfer responsibility for delivery of a message to a broker using
494
+ [code Tx]
477
495
478
496
- ensure (ahead of time) that the target queue exists and is durable,
479
497
@@ -493,6 +511,37 @@ A commit is not required after every message: batching of publications
493
511
may be done, depending on the precise delivery guarantees the
494
512
publishing application requires.
495
513
514
+ To transfer responsibility for delivery of a message to a broker using
515
+ Publisher Confirms
516
+
517
+ - ensure (ahead of time) that the target queue is durable,
518
+
519
+ - select [code Confirm] mode using [code IModel.ConfirmSelect],
520
+
521
+ - publish the message with "mandatory" flag set and [code
522
+ DeliveryMode] set equal to 2,
523
+
524
+ - listen for acknowledgements and negative acknowledgments by setting
525
+ the [code IModel.BasicAcks] and [code BasicNacks] event handlers.
526
+
527
+ Once a broker acknowledges a message via the [code BasicAcks] handler,
528
+ it has taken responsibility for keeping the message on disk and on the
529
+ target queue until some other application retrieves and acknowledges
530
+ the message.
531
+
532
+ If a broker rejects a message via the [code BasicNacks] handler, the
533
+ publisher may assume that the message was lost or otherwise
534
+ undeliverable.
535
+
536
+ Note that for unroutable messages are not considered failures and are
537
+ both [code Basic.Return'ed] and [code Basic.Ack'ed]. So, if the
538
+ "mandatory" or "immediate" are used, the client must also listen for
539
+ returns by setting the [code IModel.BasicReturn] handler.
540
+
541
+ Also note that the [code Tx] and [code Confirm] modes are mutually
542
+ exclusive on any one channel, so it is not possible to mix the two
543
+ methods described above.
544
+
496
545
Responsibility can also be placed with an external database, even
497
546
further along the chain - see the section on interaction with external
498
547
resources below.
@@ -544,6 +593,13 @@ consuming side before some kind of failure occurs. In these
544
593
situations, there will be partial duplication of a transaction: some
545
594
of the messages in the transaction will be delivered more than once.
546
595
596
+ Alternatively, rather than implement the round-trip logic manually, a
597
+ client may use Publisher Confirms. By enabling Confirm mode on a
598
+ channel, a client is requesting that the broker acknowledge or
599
+ negatively acknowledge all messages sent on the channel from that
600
+ point on. See the instructions from Responsibility Transfer on how to
601
+ use confirms.
602
+
547
603
Deciding on a message-resend policy can be difficult. Some simple
548
604
resend strategies are:
549
605
0 commit comments