Last active
August 4, 2018 14:26
-
-
Save simodima/95d7457fd5d7058fbd6b6efffb619364 to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* Assume that we're using a message bus which is able to | |
* retry failed messages with a custom retry delay. | |
*/ | |
class FetchCarMessageHandler | |
{ | |
public function handle(Message $msg) | |
{ | |
try { | |
$id = (int)$msg->getContent(); | |
$cars = $client->get('/car/'.$id); | |
return Result::success($cars); | |
} catch (TimeoutException $e) { | |
$lastBackoff = $msg->getLastBackoff(); | |
// The infrastructure layer will automagically retry the message after XYZ seconds | |
return Result::retryAfter($lastBackoff * 2, $msg); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment