1. Go to this page and download the library: Download phpgears/cqrs-async library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpgears / cqrs-async example snippets
use Gears\CQRS\Async\AsyncCommandBus;
use Gears\CQRS\Async\Serializer\JsonCommandSerializer;
use Gears\CQRS\Async\Discriminator\ParameterCommandDiscriminator;
/* @var \Gears\CQRS\CommandBus $commandBus */
/* @var Gears\CQRS\Async\CommandQueue $commandQueue */
$commandQueue = new CustomCommandQueue(new JsonCommandSerializer());
$asyncCommandBus new AsyncCommandBus(
$commandBus,
$commandQueue,
new ParameterCommandDiscriminator('async')
);
$asyncCommand = new CustomCommand(['async' => true]);
$asyncCommandBus->handle($asyncCommand);
use Gears\CQRS\Async\ReceivedCommand;
use Gears\CQRS\Async\Serializer\JsonCommandSerializer;
/* @var \Gears\CQRS\Async\AsyncCommandBus $asyncCommandBus */
/* @var your_message_queue_manager $queue */
$serializer = new JsonCommandSerializer();
while (true) {
$message = $queue->getMessage();
if ($message !== null) {
$command = new ReceivedCommand($serializer->fromSerialized($message));
$asyncCommandBus->handle($command);
}
}
use Gears\CQRS\Async\AbstractCommandQueue;
class CustomCommandQueue extends AbstractCommandQueue
{
public function send(Command $command): void
{
// Do the actual enqueue of $this->getSerializedCommand($command);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.