PHP code example of mgdigital / busque

1. Go to this page and download the library: Download mgdigital/busque 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/ */

    

mgdigital / busque example snippets




use MGDigital\BusQue as BusQue;

// The preferred client is PHPRedis:
$client = new Redis();
$adapter = new BusQue\Redis\PHPRedis\PHPRedisAdapter($client);

// A Predis adepter is use cases:
$serializer = new BusQue\Serializer\PHPCommandSerializer();

// The MD5 generator creates an ID unique to the serialized command:
$idGenerator = new BusQue\IdGenerator\Md5IdGenerator($serializer);

$implementation = new BusQue\Implementation(
    // Puts all commands into the "default" queue:
    new BusQue\QueueResolver\SimpleQueueResolver('default'), 
    $serializer,
    $idGenerator,
    // The Redis driver is used as both the queue and scheduler:
    $driver,
    $driver,
    // Always returns the current time:
    new BusQue\SystemClock(),
    // Inject your command bus here:
    new BusQue\Tactician\CommandBusAdapter($commandBus),
    // Inject your logger here:
    new Psr\Log\NullLogger()
);

$busQue = new BusQue\BusQue($implementation);



$command = new SendEmailCommand('[email protected]', 'Hello Joe!');

$commandBus->handle(new BusQue\QueuedCommand($command));

// or

$busQue->queueCommand($command);



$busQue->workQueue('default'); // Hello Joe!



$commandBus->handle(new BusQue\ScheduledCommand($command, new \DateTime('+1 minute')));

// or

$busQue->scheduleCommand($command, new \DateTime('+1 minute'));



$busQue->workSchedule(); // 1 minute later... Hello Joe!



$productId = 123;
$command = new SyncStockLevelsWithExternalApiCommand($productId);

$uniqueCommandId = 'SyncStock' . $productId; 

$commandBus->handle(new BusQue\QueuedCommand($command, $uniqueCommandId));



echo $busQue->getQueuedCount($queueName); // 0



$queues = $busQue->listQueues(); // ['SendEmailCommand', 'SyncStockCommand']



$busQue->purgeCommand($queueName, $uniqueCommandId);



$busQue->deleteQueue($queueName);



$ids = $busQue->listQueuedIds($queueName); // ['command1id', 'command2id']



$ids = $busQue->listInProgressIds($queueName); // []



$command = $busQue->getCommand($queueName, $uniqueCommandId);