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

Enqueue Bundle Laravel Package

disjfa/enqueue-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Run composer require disjfa/enqueue-bundle in your Laravel project (note: this is a Symfony bundle, but can be adapted for Laravel via bridge packages like php-enqueue/laravel-ext).

  2. Configure DSN Add the Enqueue DSN to your .env:

    ENQUEUE_DSN=mysql://user:password@localhost:3306/database
    

    (For Laravel, ensure compatibility with the underlying enqueue library, e.g., php-enqueue/amqp-ext or php-enqueue/doctrine-ext.)

  3. Register the Bundle In config/app.php, add:

    'providers' => [
        // ...
        Disjfa\EnqueueBundle\DisjfaEnqueueBundle::class,
    ],
    
  4. Define Routes Create routes/disjfa_enqueue.php (Laravel) or append to config/routes/disjfa_enqueue.yaml (Symfony):

    Route::prefix('enqueue')->group(function () {
        Route::get('/consume', [\Disjfa\EnqueueBundle\Controller\ConsumerController::class, 'consume']);
    });
    
  5. First Use Case Trigger a test message via a command or HTTP endpoint, then verify consumption via the /consume route.


Implementation Patterns

Core Workflows

  1. Message Production Use the EnqueueClient (injected via dependency injection) to publish messages:

    use Enqueue\Client\Producer;
    use Enqueue\AmqpExt\AmqpConnectionFactory;
    
    $connectionFactory = new AmqpConnectionFactory(['dsn' => env('ENQUEUE_DSN')]);
    $producer = new Producer($connectionFactory);
    $producer->send(new Message('Hello, Queue!'));
    
  2. Consumer Setup Extend Disjfa\EnqueueBundle\Consumer\ConsumerInterface to define custom logic:

    namespace App\Consumers;
    
    use Disjfa\EnqueueBundle\Consumer\ConsumerInterface;
    use Enqueue\Client\Message;
    
    class MyConsumer implements ConsumerInterface {
        public function consume(Message $message) {
            // Process message (e.g., parse JSON payload, trigger Laravel jobs)
            logger($message->getBody());
        }
    }
    
  3. Route Integration Map consumers to routes in config/routes/disjfa_enqueue.yaml:

    disjfa_enqueue.consumer:
        path: /consume/my-consumer
        methods: [GET]
        defaults: { _controller: 'DisjfaEnqueueBundle:Consumer/myConsumer' }
    
  4. Laravel-Specific Adaptations

    • Use php-enqueue/laravel-ext for Laravel service provider integration.
    • Bridge Enqueue messages to Laravel queues via Illuminate\Bus\Queueable:
      $producer->send(new Message(json_encode(['job' => NewJob::dispatch()])));
      
  5. Background Processing Schedule consumers via Laravel’s schedule:run or Symfony’s console commands:

    // In a Laravel command
    $this->call('enqueue:consume', ['--consumer' => 'my_consumer']);
    

Gotchas and Tips

Pitfalls

  1. DSN Compatibility

    • The bundle assumes Symfony’s enqueue-bundle DSN format. For Laravel, ensure the underlying php-enqueue extension (e.g., amqp, doctrine) is installed:
      pecl install enqueue-amqp
      
    • Test DSN with php-enqueue/console:
      vendor/bin/enqueue-consumer --dsn="mysql://..." --queue=default
      
  2. Route Conflicts

    • Laravel’s routing system may clash with Symfony-style annotations. Use explicit route namespaces:
      Route::namespace('Disjfa\EnqueueBundle\Controller')->group(...);
      
  3. Message Serialization

    • Default Message objects use raw strings. For Laravel, serialize payloads to JSON:
      $producer->send(new Message(json_encode(['data' => $payload])));
      
  4. Consumer Lifecycle

    • Consumers run indefinitely. Terminate gracefully with signals (e.g., SIGTERM) or Laravel’s Artisan::terminate().

Debugging

  • Log Consumer Output Redirect logs to Laravel’s storage/logs/laravel.log:

    Monolog\Logger::getInstance('enqueue')->pushHandler(new StreamHandler(storage_path('logs/enqueue.log')));
    
  • Check Queue Backlog Use enqueue:browse (Symfony) or php-enqueue/console:

    vendor/bin/enqueue-browse --dsn="mysql://..."
    

Extension Points

  1. Custom Transports Override the EnqueueClient in Laravel’s AppServiceProvider:

    $this->app->bind(Producer::class, function () {
        return new Producer(new AmqpConnectionFactory(['dsn' => env('ENQUEUE_DSN')]));
    });
    
  2. Middleware for Messages Attach middleware to consumers (e.g., validation, retries):

    $consumer->setMiddleware(new RetryMiddleware(3));
    
  3. Laravel Queue Integration Proxy Enqueue messages to Laravel’s Illuminate\Queue:

    $producer->send(new Message(json_encode(['queue' => 'default', 'payload' => $job])));
    
  4. Testing Use enqueue/fake for unit tests:

    $this->app->bind(Producer::class, function () {
        return new Producer(new FakeConnection());
    });
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky