Skip to content

Instantly share code, notes, and snippets.

@toretto460
Last active August 4, 2018 14:26
Show Gist options
  • Save toretto460/95d7457fd5d7058fbd6b6efffb619364 to your computer and use it in GitHub Desktop.
Save toretto460/95d7457fd5d7058fbd6b6efffb619364 to your computer and use it in GitHub Desktop.
<?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