PQueueBundle is a Symfony bundle that integrates Pqueue, a minimalist PHP library for processing background messages using a single persistent CLI.

michelphp ca5fa5520f Initialize version 0.0.1-alpha of PQueueBundle hai 1 día
src ca5fa5520f Initialize version 0.0.1-alpha of PQueueBundle hai 1 día
tests ca5fa5520f Initialize version 0.0.1-alpha of PQueueBundle hai 1 día
.gitignore ca5fa5520f Initialize version 0.0.1-alpha of PQueueBundle hai 1 día
LICENSE ca5fa5520f Initialize version 0.0.1-alpha of PQueueBundle hai 1 día
README.md ca5fa5520f Initialize version 0.0.1-alpha of PQueueBundle hai 1 día
composer.json ca5fa5520f Initialize version 0.0.1-alpha of PQueueBundle hai 1 día

README.md

PQueueBundle

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.