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 adds a
Confidence Score: 4/5Safe to merge after confirming the open discussions from earlier review rounds are resolved; the core logic is sound but the failover mechanism has edge cases worth closing before shipping. The implementation is well-structured and the test suite is thorough. However, the failover catch block covers only \Exception, meaning \Error subclasses thrown by adapters (e.g. \TypeError from a broken process() implementation) escape the loop and propagate immediately without trying subsequent adapters. That gap was raised in a prior round and remains unaddressed in the diff, leaving the failover guarantee incomplete for a real-world failure class that adapters can plausibly produce. src/Utopia/Messaging/Messenger.php — the catch block and the soft-failure/getMaxMessagesPerRequest contract warrant a second look before merge. Important Files Changed
Reviews (2): 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.
Based on PR utopia-php#115 by TorstenDittmann. Adds Messenger class that orchestrates multiple adapters with automatic failover.
d4b60e4 to
834d575
Compare
| * 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.
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: