PHP code example of rezzza / command-bus

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

    

rezzza / command-bus example snippets


class ShortenUrlCommand
{
    private $longUrl;

    public function __construct($longUrl)
    {
        $this->longUrl = $longUrl;
    }

    public function getLongUrl()
    {
        return $this->longUrl;
    }
}

do {
    $redis    = new \Redis();
    $redis->connect('......');

    $handlerLocator = new Rezzza\CommandBus\Infra\Handler\MemoryHandlerLocator();
    // add some handlers ...
    $directBus         = new Rezzza\CommandBus\Infra\Provider\Direct\DirectBus($handlerLocator);
    $failStrategy      = new Rezzza\CommandBus\Domain\Consumer\FailStrategy\NoneStrategy();
    $redisKeyGenerator = new CommandBus\Infra\Provider\Redis\RedisKeyGenerator();
    $serializer        = new CommandBus\Infra\Serializer\NativeSerializer();

    $consumer = new Rezzza\CommandBus\Domain\Consumer\Consumer(
        new Rezzza\CommandBus\Infra\Provider\Redis\RedisConsumerProvider($redis, $redisKeyGenerator, $serializer),
        $directBus,
        $failStrategy
    );

    $consumer->consume('FooCommand');
    sleep(1); // yep ...
} while (true);