Queues

    The Lumen queue service provides a unified API across a variety of different queue back-ends. Queues allow you to defer the processing of a time consuming task, such as performing a task on a remote server, until a later time which drastically speeds up web requests to your application.

    Like many other parts of the framework, Lumen's queued jobs function identically to Laravel's queued jobs. So, to learn more about queuing jobs in Lumen, please review the full Laravel queue documentation.

    If you would like to thoroughly customize the queue configuration, then you must copy the entire vendor/laravel/lumen-framework/config/queue.php file to the config directory in the root of your project and adjust the necessary configuration options as needed. If the config directory does not exist, then you should create it.

    Driver Prerequisites

    Database

    In order to use the database queue driver, you will need database tables to hold the jobs and failures:

    Other Queue Dependencies

    The following dependencies are needed for the listed queue drivers:

    • Amazon SQS: aws/aws-sdk-php ~3.0
    • Beanstalkd:
    • Redis: predis/predis ~1.0

    Differences From Laravel

    However, there are a few minor differences that we will discuss now. First, let's talk about how queued jobs are generated in Lumen.

    Generators

    Lumen does not include generators for automatically creating new Job classes. Instead, you should copy the ExampleJob class that is included with the framework. This class provides the basic structure that is shared by every Job class. The base Job that is used by the ExampleJob already includes the needed InteractsWithQueue, , and SerializesModels traits:

    Dispatching Jobs

    Again, you should consult the full Laravel documentation for complete information on dispatching queued jobs; however, just like in the Laravel framework, you may use the dispatch function to dispatch jobs from anywhere within your Lumen application: