Created
September 24, 2022 08:44
-
-
Save dgafka/e726a5748a5b381cda68b35cb7d173c9 to your computer and use it in GitHub Desktop.
Working with asynchronous errors in PHP
This file contains 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 | |
#[AsMessageHandler] | |
class NotificationServiceHandler | |
{ | |
public function __invoke(OrderWasPlaced $message) | |
{ | |
$this->messageBus->handle(new SendPlaceOrderEmail()); | |
} | |
} | |
#[AsMessageHandler] | |
class PaymentServiceHandler | |
{ | |
public function __invoke(OrderWasPlaced $message) | |
{ | |
$this->messageBus->handle(new MakePayment()); | |
} | |
} | |
#[AsMessageHandler] | |
class OrderPlacedEmailSender | |
{ | |
public function __invoke(SendPlaceOrderEmail $message) | |
{ | |
// send an SMS message! | |
} | |
} | |
#[AsMessageHandler] | |
class Payment | |
{ | |
public function __invoke(MakePayment $message) | |
{ | |
// take a payment from credit card | |
} | |
} | |
# In your symfon config, making handlers asynchronous | |
framework: | |
messenger: | |
routing: | |
# async is whatever name you gave your transport above | |
'OrderWasPlaced': async | |
'SendPlaceOrderEmail': async | |
'MakePayment': async |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment