Skip to content

Commit 682ee05

Browse files
author
Emile Joubert
committed
Merged bug24222 into default
2 parents b64a48b + 4991a21 commit 682ee05

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

docs/wikipages/data.MessagingPatterns.txt

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,30 @@ transactions are active is underspecified in both versions 0-8 and 0-9
120120
of the AMQP specification, and different server implementations behave
121121
in different ways.
122122

123-
Finally, the fact that a message was flagged "mandatory", and
123+
Additionally, the fact that a message was flagged "mandatory", and
124124
successfully enqueued on one or more queues, is no guarantee of its
125125
eventual receipt: most trivially, the queue could be deleted before
126126
the message is processed, but other situations, like the use of the
127127
[code noAck] flag by a message consumer, can also make the guarantees
128128
provided by "mandatory" and "immediate" conditional.
129129

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+
130147
**** Receiving replies
131148

132149
AMQP's Basic-class content header ([code IBasicProperties]) contains a
@@ -471,9 +488,10 @@ two AMQP clients involved: the publisher, and the consumer.
471488
Responsibility can be partially transferred to the broker by using
472489
durable queues, durable exchanges, persistent-mode delivered messages
473490
(with [code DeliveryMode] set equal to 2), and [code Tx]-class
474-
transactions.
491+
transactions or Publisher Confirms.
475492

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]
477495

478496
- ensure (ahead of time) that the target queue exists and is durable,
479497

@@ -493,6 +511,37 @@ A commit is not required after every message: batching of publications
493511
may be done, depending on the precise delivery guarantees the
494512
publishing application requires.
495513

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+
496545
Responsibility can also be placed with an external database, even
497546
further along the chain - see the section on interaction with external
498547
resources below.
@@ -544,6 +593,13 @@ consuming side before some kind of failure occurs. In these
544593
situations, there will be partial duplication of a transaction: some
545594
of the messages in the transaction will be delivered more than once.
546595

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+
547603
Deciding on a message-resend policy can be difficult. Some simple
548604
resend strategies are:
549605

0 commit comments

Comments
 (0)