The built-in recovery computes reconnect delays in lib/recovery.js with a fixed strategy: an exponential base capped at maxDelay, plus symmetric jitter around the base (offset = Math.random() * jitterPart * 2 - jitterPart). Two consequences for consumers:
- the jitter shape is fixed — full jitter (
uniform[0, cap]), decorrelated jitter, or fixed-step schedules are not expressible;
- the cap applies to the base before jitter, so the effective delay can exceed
maxDelay by up to the jitter fraction (with jitter: 1, up to 2× maxDelay).
Proposal: accept an optional function in the recovery options, following the precedent of the functional setup option:
await amqplib.connect(url, {
recovery: {
// ms; attempt starts at 1; falls back to the built-in strategy when absent
calculateDelay: (attempt) => number,
},
});
When absent, behavior is unchanged. normaliseRecoveryOptions currently drops unknown keys, so the addition is backward-compatible.
Context: we maintain an AMQP adapter built on the v2 recovery (Connectum framework). Some strategies can be approximated with the numeric knobs (e.g. full jitter via jitter: 1 plus halved initialDelay/maxDelay), but that is fragile against internal changes and does not cover step schedules or other shapes. A supported hook would remove the need to own a separate reconnect loop just for delay control.
Happy to send a PR if the direction is acceptable.
The built-in recovery computes reconnect delays in
lib/recovery.jswith a fixed strategy: an exponential base capped atmaxDelay, plus symmetric jitter around the base (offset = Math.random() * jitterPart * 2 - jitterPart). Two consequences for consumers:uniform[0, cap]), decorrelated jitter, or fixed-step schedules are not expressible;maxDelayby up to the jitter fraction (withjitter: 1, up to 2×maxDelay).Proposal: accept an optional function in the recovery options, following the precedent of the functional
setupoption:When absent, behavior is unchanged.
normaliseRecoveryOptionscurrently drops unknown keys, so the addition is backward-compatible.Context: we maintain an AMQP adapter built on the v2 recovery (Connectum framework). Some strategies can be approximated with the numeric knobs (e.g. full jitter via
jitter: 1plus halvedinitialDelay/maxDelay), but that is fragile against internal changes and does not cover step schedules or other shapes. A supported hook would remove the need to own a separate reconnect loop just for delay control.Happy to send a PR if the direction is acceptable.