<?php
use Common\Queue\Interfaces\JobInterface;
class ExampleJob implements JobInterface
{
private $id = 0;
private $string = 'hello';
private $array = ['key' => 'value'];
public function handle(array $attributes): void
{
echo ('Done.');
}
}use TestJob;
use Common\Queue\Dispatcher;
/** @var Dispatcher $dispatcher */
$dispatcher = $this->di->get('queue.dispatcher');
$exampleJob = new ExampleJob();
$dispatcher->dispatch($exampleJob, ['id' => 1, 'message' => 'foo bar']);The ExampleJob instance will be serialized using serialize function and then deserialized when consuming the message.
To run the queue worker, execute the following command:
./bin/robo queue:workTo run the worker on a specific queue, specify it using the queue option:
./bin/robo queue:work --queue=defaultTo prevent the output, use the silent option:
./bin/robo queue:work --silentIf you want to handle the next job only, use once:
./bin/robo queue:work --once