michel / pqueue-bundle
PQueueBundle is a Symfony bundle that integrates Pqueue, a minimalist PHP library for processing background messages using a single persistent CLI.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Type:symfony-bundle
pkg:composer/michel/pqueue-bundle
Requires
- php: >=7.4
- ext-pdo: *
- michel/pqueue: ^0.0.1@alpha
- monolog/monolog: ^2.10|^3.0
- symfony/config: ^5.4 || ^6.0 || ^7.0
- symfony/console: ^5.4 || ^6.0 || ^7.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
- symfony/yaml: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^9.6|^10.5
- symfony/framework-bundle: ^5.4 || ^6.0 || ^7.0
This package is not auto-updated.
Last update: 2025-12-16 12:13:20 UTC
README
Integration of michel/pqueue into Symfony.
Installation
composer require michel/pqueue-bundle
Configuration
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'
Usage
1. Create a Message and Handler
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.
2. Dispatch a Message
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));
}
3. Run the Worker
php bin/console pqueue:worker:run
License
This bundle is released under the MPL-2.0 License.