feat: add opt-in automatic recovery for promise and callback APIs#833
Open
ShiriNmi1520 wants to merge 6 commits intoamqp-node:mainfrom
Open
feat: add opt-in automatic recovery for promise and callback APIs#833ShiriNmi1520 wants to merge 6 commits intoamqp-node:mainfrom
ShiriNmi1520 wants to merge 6 commits intoamqp-node:mainfrom
Conversation
Signed-off-by: Ivan <[email protected]>
Signed-off-by: Ivan <[email protected]>
Signed-off-by: Ivan <[email protected]>
Signed-off-by: Ivan <[email protected]>
Signed-off-by: Ivan <[email protected]>
Signed-off-by: Ivan <[email protected]>
Collaborator
|
Thank you for this @ShiriNmi1520, it looks like a very comprehensive piece of work. I've have some time off next week and will review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a generic, opt-in recovery mechanism to
amqplibfor both public APIs:require('amqplib'))require('amqplib/callback_api'))Recovery is enabled only when
connect(..., { recovery: ... })is provided, so the default behaviour remains unchanged.Motivation
Fix #25
What changed
lib/recovery.jschannel_api.jscallback_api.jsREADME.mdfor usage/options/eventstest/recovery.jsRecovery options
initialDelaymaxDelayfactorjittermaxRetries(also acceptsmaxAttempts)setup(model, client[, done])called after each successful connect/reconnectMermaid sequence chart
sequenceDiagram autonumber participant App participant Client as amqplib (recovering client) participant Broker as RabbitMQ App->>Client: connect(url, { recovery }) Client->>Broker: open TCP + AMQP handshake Broker-->>Client: open-ok Client->>Client: run recovery.setup(...) Client-->>App: emit "connect" Note over Broker,Client: normal operation Broker-x Client: socket/connection closed Client-->>App: emit "disconnect" Client-->>App: emit "reconnectScheduled" loop retry with backoff+jitter Client->>Broker: reconnect + handshake alt success Broker-->>Client: open-ok Client->>Client: run recovery.setup(...) Client-->>App: emit "connect" else failed and retries remain Client-->>App: emit "connectFailed" Client-->>App: emit "reconnectScheduled" end end alt retries exhausted Client-->>App: emit "reconnectFailed" endBackward compatibility
recoveryis explicitly configured.Notes / limitations