PHP code example of kafka-bus / worker

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

    

kafka-bus / worker example snippets




use KafkaBus\Worker\Options;
use KafkaBus\Worker\Registry\MemoryWorkerRegistry;
use KafkaBus\Worker\Worker;
use KafkaBus\Worker\WorkerRunnerFactory;

[$bus, $topics] = : [
            'group.id' => 'orders-service',
            'auto.offset.reset' => 'earliest',
        ],
        consumerTimeout: 2000,
    ),
));

$runner = (new WorkerRunnerFactory($workers))->create($bus, 'orders-worker');
$runner->run();

pcntl_async_signals(true);
pcntl_signal(SIGTERM, static fn () => $runner->forceStop());
pcntl_signal(SIGINT, static fn () => $runner->forceStop());

$runner->run();