PHP code example of azaharizaman / nexus-outbox

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

    

azaharizaman / nexus-outbox example snippets


use Nexus\Outbox\Domain\OutboxEnqueueCommand;
use Nexus\Outbox\Services\InMemoryOutboxStore;
use Nexus\Outbox\Services\OutboxService;
use Nexus\Outbox\Services\SystemClock;
use Nexus\Outbox\ValueObjects\DedupKey;
use Nexus\Outbox\ValueObjects\EventTypeRef;
use Nexus\Outbox\ValueObjects\TenantId;

$tenantId = new TenantId('tenant-1');
$store = new InMemoryOutboxStore();
$clock = new SystemClock();
$outbox = new OutboxService($store, $store, $clock);

$now = $clock->now();
$leaseExpiresAt = $now->modify('+5 minutes');

$result = $outbox->enqueue(new OutboxEnqueueCommand(
    $tenantId,
    new DedupKey($streamEventId),
    new EventTypeRef($eventTypeFqcn),
    $payload,
    $metadata,
    $correlationId,
    $causationId,
    $now,
));

$claimed = $outbox->claimNextPending($tenantId, $leaseExpiresAt);
if ($claimed !== null) {
    // publish to external bus, then:
    $outbox->markSent($tenantId, $claimed->id, $claimed->claimToken);
}