Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Queue Manager Bundle Laravel Package

arko/queue-manager-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle
    composer require arko/queue-manager-bundle:dev-master
    
  2. Enable the Bundle Add to app/AppKernel.php:
    new Arko\QueueManagerBundle\ArkoQueueManagerBundle(),
    
  3. First Use Case: Queue a Simple Task Inject the service into a controller or command:
    use Arko\QueueManagerBundle\QueueManager;
    
    class MyController extends Controller
    {
        public function __construct(QueueManager $queueManager)
        {
            $this->queueManager = $queueManager;
        }
    
        public function enqueueTask()
        {
            $this->queueManager->add(function() {
                // Your task logic (e.g., send email, process data)
                \Log::info('Task executed!');
            }, 'email_queue');
    
            return 'Task queued!';
        }
    }
    

Implementation Patterns

Core Workflow

  1. Enqueue Callables Use add(callable, string $queueName) to defer execution:

    $queueManager->add(fn() => $this->sendWelcomeEmail($user), 'email_queue');
    
  2. Process Queues Trigger processing via CLI or HTTP endpoint:

    // CLI Command Example
    $queueManager->process('email_queue');
    
  3. Named Queues for Isolation Organize tasks by purpose (e.g., email_queue, report_queue).

Integration Tips

  • Laravel Commands Create a custom Artisan command to process queues:

    namespace App\Console\Commands;
    
    use Arko\QueueManagerBundle\QueueManager;
    use Illuminate\Console\Command;
    
    class ProcessQueues extends Command
    {
        protected $signature = 'queues:process {queue?}';
        protected $description = 'Process a specific queue or all queues';
    
        public function handle(QueueManager $queueManager)
        {
            $queue = $this->argument('queue') ?? 'default';
            $queueManager->process($queue);
            $this->info("Processed queue: {$queue}");
        }
    }
    
  • Dependency Injection Prefer constructor injection for testability:

    public function __construct(QueueManager $queueManager) {
        $this->queueManager = $queueManager;
    }
    
  • Contextual Queues Use dynamic queue names for scoped tasks:

    $queueManager->add(fn() => $this->cleanup($userId), "cleanup_{$userId}");
    

Gotchas and Tips

Pitfalls

  1. No Persistence Queues are in-memory only (cleared after processing). Use a database or Redis for persistence:

    composer require predis/predis
    

    Workaround: Implement a custom storage adapter (see Extension Points).

  2. Blocking Calls process() executes callables synchronously. For async processing, wrap in a queue worker (e.g., Laravel Queues).

  3. Singleton Scope The QueueManager is a singleton. Avoid stateful operations across requests.

Debugging

  • Queue Contents Inspect queues via reflection (not officially supported):

    $reflection = new \ReflectionClass($queueManager);
    $property = $reflection->getProperty('queues');
    $property->setAccessible(true);
    var_dump($property->getValue($queueManager));
    
  • Logging Add logging to callables for visibility:

    $queueManager->add(function() {
        \Log::debug('Processing task...');
        // Task logic
    }, 'debug_queue');
    

Extension Points

  1. Custom Storage Override the QueueManager service to use a persistent store:

    # config/services.yaml
    services:
        Arko\QueueManagerBundle\QueueManager:
            arguments:
                $storage: '@your.custom.storage'
    
  2. Priority Queues Extend the bundle to support priority levels by modifying the add() method:

    $queueManager->add($callable, 'queue_name', 1); // Priority 1
    
  3. Event Dispatching Trigger events before/after processing:

    $queueManager->process('queue_name', function() {
        event(new QueueProcessed('queue_name'));
    });
    

Tips

  • Use for Lightweight Tasks Ideal for non-critical, short-lived operations (e.g., caching, logging).
  • Combine with Laravel Queues For heavy lifting, offload to Laravel’s queue system:
    $queueManager->add(function() {
        dispatch(new ProcessHeavyTask());
    }, 'laravel_queue');
    
  • Testing Mock the QueueManager in tests:
    $mockQueue = $this->createMock(QueueManager::class);
    $mockQueue->expects($this->once())->method('add');
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle