1. Go to this page and download the library: Download assegaiphp/beanstalkd 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/ */
use Assegai\Core\Queues\Attributes\InjectQueue;
use Assegai\Core\Queues\Interfaces\QueueInterface;
readonly class NotificationsService
{
public function __construct(
#[InjectQueue('beanstalk.notifications')] private QueueInterface $queue
) {}
public function send(array $payload): void
{
$this->queue->add($payload);
}
}
use Assegai\Core\Queues\Attributes\Processor;
use Assegai\Core\Queues\WorkerHost;
use Assegai\Core\Queues\QueueProcessResult;
use Assegai\Core\Queues\Interfaces\QueueProcessResultInterface;
#[Processor('beanstalk.notifications')]
class NotificationsConsumer extends WorkerHost
{
public function process(callable $callback): QueueProcessResultInterface
{
$job = $callback();
$data = $job->data;
echo "Dispatching notification: {$data->message}" . PHP_EOL;
return new QueueProcessResult(data: ['status' => 'sent'], job: $job);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.