PQueueBundle is a Symfony bundle that integrates Pqueue, a minimalist PHP library for processing background messages using a single persistent CLI.
|
|
1 일 전 | |
|---|---|---|
| src | 1 일 전 | |
| tests | 1 일 전 | |
| .gitignore | 1 일 전 | |
| LICENSE | 1 일 전 | |
| README.md | 1 일 전 | |
| composer.json | 1 일 전 |
Integration of michel/pqueue into Symfony.
composer require michel/pqueue-bundle
Create a configuration file config/packages/pqueue.yaml:
pqueue:
transport:
class: 'Michel\PQueue\Transport\FilesystemTransport'
options:
directory: '%kernel.project_dir%/var/pqueue'
handlers:
# Auto-discovery of handlers in these directories
sources:
- '%kernel.project_dir%/src/MessageHandler'
First, define a message class:
// src/Message/EmailNotification.php
namespace App\Message;
class EmailNotification
{
public function __construct(
public int $userId
) {}
}
Then, create a handler for it:
// src/MessageHandler/EmailNotificationHandler.php
namespace App\MessageHandler;
use App\Message\EmailNotification;
class EmailNotificationHandler
{
public function __invoke(EmailNotification $message): void
{
// Process message for user $message->userId
}
}
Note: The handler is automatically discovered if it is in one of the configured source directories. It must implement __invoke with a single argument type-hinted with the message class.
Inject Michel\PQueue\PQueueDispatcher and send a message:
use Michel\PQueue\PQueueDispatcher;
use App\Message\EmailNotification;
public function index(PQueueDispatcher $dispatcher)
{
$dispatcher->send(new EmailNotification(123));
}
php bin/console pqueue:worker:run
This bundle is released under the MPL-2.0 License.