feat: add Messenger class for multiple adapter failover support - #128
feat: add Messenger class for multiple adapter failover support#128deepshekhardas wants to merge 1 commit into
Conversation
Greptile SummaryThis PR introduces a
Confidence Score: 4/5The Messenger class is well-structured and the tests are thorough, but several defects flagged in earlier review rounds remain unaddressed in the code. Three issues noted in prior review threads are still present: the catch block in send() only catches \Exception so any \Error bypasses failover; $this->adapters[0] is accessed directly in multiple methods, silently breaking for non-zero-indexed input arrays; and the constructor does not call array_values() to normalise keys. Files Needing Attention: src/Utopia/Messaging/Messenger.php — the catch-block scope and array-key normalisation issues need to be fixed before the failover contract can be considered reliable. Important Files Changed
Reviews (5): Last reviewed commit: "feat: add Messenger class for multiple a..." | Re-trigger Greptile |
| if (! \is_a($message, $messageType)) { | ||
| throw new \Exception( | ||
| 'Invalid message type. Expected "' | ||
| .$messageType | ||
| .'", got "' | ||
| .\get_class($message) |
There was a problem hiding this comment.
Failover skipped on
\Error subclasses
The catch block only catches \Exception, so any \TypeError or other \Error thrown by an adapter will propagate immediately without trying the next adapter, defeating the purpose of failover. Changing to \Throwable would cover both \Exception and \Error hierarchies.
| * successful adapter. | ||
| * | ||
| * @param Message $message The message to send. | ||
| * @return array{ |
There was a problem hiding this comment.
Soft-failure responses bypass failover silently
Messenger::send() only falls back on thrown exceptions, so an adapter that returns a response with deliveredTo: 0 and all-failure results is treated as "success" — the second adapter is never tried. This is documented by the test, but the behaviour may surprise callers who expect the Messenger to be smarter about delivery failures. At minimum, the PHPDoc and README should warn that "failure" payloads without an exception are returned as-is without attempting the next adapter, so callers must inspect deliveredTo themselves.
|
Following up - this PR adds Messenger class for multiple adapter failover. Ready for review. |
Based on PR utopia-php#115 by TorstenDittmann. Adds Messenger class that orchestrates multiple adapters with automatic failover.
Port of PR #115 by TorstenDittmann.
Adds Messenger class that orchestrates multiple messaging adapters with automatic failover. If one adapter fails, it falls back to the next in the list.
Changes: