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 | |
class CommandController | |
{ | |
public function execute(Request $request, CommandBus $commandBus): Response | |
{ | |
$routingKey = $request->headers->get('X-Routing-Key'); | |
$commandBus->sendWithRouting( | |
routingKey: $routingKey, |
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
/** RabbitMQ Consumer example */ | |
#[RabbitConsumer( | |
endpointId: 'transaction_handler', | |
queueName: 'transactions', | |
finalFailureStrategy: FinalFailureStrategy::STOP | |
)] | |
public function processTransactionEvent(TransactionEvent $event): void | |
{ | |
// Handle Transaction Event | |
} |
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
/** RabbitMQ Consumer example */ | |
#[InstantRetry(retryTimes: 2, exceptions: [NetworkException::class])] | |
#[RabbitConsumer(endpointId: 'transaction_handler', queueName: 'transactions')] | |
public function processTransactionEvent(TransactionEvent $event): void | |
{ | |
// handle | |
} | |
/** Kafka Consumer example */ | |
#[InstantRetry(retryTimes: 2)] // no exceptions given, meaing retry on all exceptions |
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
#[InstantRetry(retryTimes: 2, exceptions: [NetworkException::class])] | |
#[RabbitConsumer(endpointId: 'transaction_handler', queueName: 'transactions')] | |
public function processTransactionEvent(TransactionEvent $event): void | |
{ | |
// handle | |
} |
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 | |
// Configuration on Publisher Side | |
public function changeBillingDetails(DistributedBus $distributedCommandBus) | |
{ | |
$distributedCommandBus->sendCommand( | |
"billing", // destination | |
"billing.changeDetails", // routingKey | |
'["personId":"123","billingDetails":"01111"]', | |
"application/json" |
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 | |
class PlaceOrdernHandler | |
{ | |
// default behaviour, first parameter is payload, second are headers | |
#[CommandHandler("place_order")] | |
public function placeOrder(PlaceOrder $payload, array $headers) {} | |
} | |
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 | |
class MessagingConfiguration | |
{ | |
#[ServiceContext] | |
public function asyncChannel() | |
{ | |
// this channel can be reused for different message handlers | |
return AmqpBackedMessageChannelBuilder::create("async_channel"); | |
} |
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 | |
class AddExecutorIdMiddleware | |
{ | |
/** | |
* @param mixed $job | |
* @param callable $next | |
* @return mixed | |
*/ | |
public function handle($job, $next) |
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 | |
PlaceOrder::dispatch($order)->onQueue('async_channel'); |
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 | |
class PlaceOrder implements ShouldQueue | |
{ | |
use Dispatchable, InteractsWithQueue, Queueable; | |
protected Order $order; | |
public function __construct(Order $order) | |
{ |
NewerOlder