@@ -6,7 +6,7 @@ source code.
6
6
7
7
** Major namespaces, interfaces and classes
8
8
9
- The API is closely modelled on the AMQP protocol specification, with
9
+ The API is closely modelled on the AMQP 0-9-1 protocol specification, with
10
10
little additional abstraction.
11
11
12
12
The core API interfaces and classes are defined in the [code
@@ -356,4 +356,73 @@ publishes a message with the "mandatory" flag set to an exchange of
356
356
357
357
** Automatic Recovery From Network Failures
358
358
359
- TODO
359
+ Network connection between clients and RabbitMQ nodes can fail.
360
+ RabbitMQ Java client supports automatic recovery of connections
361
+ and topology (queues, exchanges, bindings, and consumers).
362
+
363
+ The automatic recovery process for many applications follows the following steps:
364
+
365
+ - Reconnect
366
+ - Restore connection listeners
367
+ - Re-open channels
368
+ - Restore channel listeners
369
+ - Restore channel [code basic.qos] setting, publisher confirms and transaction settings
370
+
371
+ Topology recovery includes the following actions, performed for every channel
372
+
373
+ - Re-declare exchanges (except for predefined ones)
374
+ - Re-declare queues
375
+ - Recover all bindings
376
+ - Recover all consumers
377
+
378
+ To enable automatic connection recovery, use
379
+ [code factory.AutomaticRecoveryEnabled = true]:
380
+ @code java
381
+ ConnectionFactory factory = new ConnectionFactory();
382
+ factory.AutomaticRecoveryEnabled = true;
383
+ // connection that will recover automatically
384
+ IConnection conn = factory.CreateConnection();
385
+
386
+ If recovery fails due to an exception (e.g. RabbitMQ node is
387
+ still not reachable), it will be retried after a fixed time interval (default
388
+ is 5 seconds). The interval can be configured:
389
+
390
+ @code java
391
+ ConnectionFactory factory = new ConnectionFactory();
392
+ // attempt recovery every 10 seconds
393
+ factory.NetworkRecoveryInterval = TimeSpan.FromSeconds(10);
394
+
395
+
396
+ ** Topology Recovery
397
+
398
+ Topology recovery involves recovery of exchanges, queues, bindings
399
+ and consumers. It is enabled by default but can be disabled:
400
+
401
+ @code java
402
+ ConnectionFactory factory = new ConnectionFactory();
403
+
404
+ Connection conn = factory.newConnection();
405
+ factory.AutomaticRecoveryEnabled = true;
406
+ factory.TopologyRecoveryEnabled = false;
407
+
408
+
409
+ ** Manual Acknowledgements and Automatic Recovery
410
+
411
+ When manual acknowledgements are used, it is possible that
412
+ network connection to RabbitMQ node fails between message
413
+ delivery and acknowledgement. After connection recovery,
414
+ RabbitMQ will reset delivery tags on all channels.
415
+
416
+ This means that [code basic.ack], [basic.nack], and [basic.reject]
417
+ with old delivery tags will cause a channel exception. To avoid this,
418
+ RabbitMQ Java client keeps track of and updates delivery tags to make them monotonically
419
+ growing between recoveries.
420
+
421
+ [code Channel.basicAck],
422
+ [code Channel.basicNack], and
423
+ [code Channel.basicReject] then translate adjusted
424
+ delivery tags into those used by RabbitMQ.
425
+
426
+ Acknowledgements with stale delivery tags will not be
427
+ sent. Applications that use manual acknowledgements and automatic
428
+ recovery must be capable of handling redeliveries.
0 commit comments