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

Null Laravel Package

enqueue/null

Null transport for Enqueue/Queue Interop: a no-op queue implementation that doesn’t send messages anywhere. Useful as a mock transport for tests and local development, while keeping the same messaging APIs and configuration style.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require enqueue/null
    

    Register the service provider in config/app.php (if not auto-discovered):

    'providers' => [
        // ...
        Enqueue\Null\NullTransport::class,
    ],
    
  2. Basic Usage The enqueue/null package provides a null transport for the PHP-Enqueue library, allowing you to mock or bypass message queues entirely. Initialize it in your Laravel app:

    use Enqueue\Null\NullTransport;
    use Enqueue\Client\Producer;
    
    $transport = new NullTransport();
    $producer = new Producer($transport);
    
  3. First Use Case Replace a real queue (e.g., RabbitMQ, Redis) with a null transport for testing, debugging, or development where queue operations are unnecessary:

    $producer->send(new Message('Hello, Null Transport!'));
    // No actual message is sent; this is a no-op.
    

Implementation Patterns

1. Dependency Injection & Mocking

  • Use in Tests Replace real transports with NullTransport in unit/integration tests to avoid external dependencies:

    $this->app->bind(Producer::class, function ($app) {
        return new Producer(new NullTransport());
    });
    
  • Conditional Queue Handling Dynamically switch between real and null transports based on environment:

    $transport = config('queue.transport') === 'null'
        ? new NullTransport()
        : new RabbitMqTransport(config('queue.rabbitmq'));
    

2. Integration with PHP-Enqueue

  • Consumers & Contexts The null transport supports the full PHP-Enqueue API, including:

    $consumer = new Consumer($transport, 'test-queue', new NullContext());
    $consumer->consume(); // No actual consumption occurs.
    
  • Error Handling Mimic real queue behavior by throwing exceptions (if needed) or silently ignoring operations.

3. Laravel-Specific Workflows

  • Queue Workers Disable queue workers entirely in config/queue.php:

    'connections' => [
        'null' => [
            'driver' => 'enqueue-null',
            'transport' => Enqueue\Null\NullTransport::class,
        ],
    ],
    

    Then dispatch jobs to the null connection:

    dispatch(new Job())->onConnection('null');
    
  • Event Queues Use for testing event listeners that rely on queues:

    Event::listen(JobDispatched::class, function () {
        // This will not actually queue anything.
        dispatch(new ProcessPodcast());
    });
    

Gotchas and Tips

Pitfalls

  • No Persistence All operations are in-memory and discarded immediately. Use only for testing or development.

    // ❌ Won't work for production:
    $producer->send(new Message('Critical task!')); // Lost forever.
    
  • Consumer Behavior Consumers will appear to run but do nothing. Avoid using them for real workloads:

    $consumer->consume(); // Runs forever but processes no messages.
    
  • Thread Safety The null transport is not thread-safe (like all in-memory transports). Not an issue for Laravel’s single-process workers, but beware in multi-process setups.

Debugging Tips

  • Verify No Side Effects Use Log::debug() to confirm messages aren’t being sent:

    $producer->send(new Message('Test'));
    Log::debug('Message sent to null transport'); // Only this log appears.
    
  • Check for Misconfigurations Ensure the transport is correctly bound in Laravel’s service container:

    php artisan config:clear
    

Extension Points

  • Custom Null Transport Extend NullTransport to log dropped messages:

    class LoggingNullTransport extends NullTransport {
        public function send(Message $message) {
            Log::info('Dropped message: ' . $message->getBody());
        }
    }
    
  • Hybrid Testing Combine with other transports for partial mocking:

    $transport = new CompositeTransport([
        new NullTransport(), // Drops messages
        new RedisTransport(), // Logs to Redis for inspection
    ]);
    
  • Performance Testing Use to benchmark queue overhead by comparing against real transports.

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.
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
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope