4

I have Laravel 5 project. This is multi-tenant project, so I have one folder project with multiple databases.

When I use php artisan queue:listen, it only works with the current database setup. I use the database queue driver, so each tenant has their own notifications table. How do I setup a queue listener to check all database jobs?

1 Answer 1

8

If you want to continue using the database driver, I would suggest setting up another database that contains all your queued jobs and failed jobs.

Although it is not in the config or mentioned by the documentation, after taking a look at the code, it looks like you should be able to add a connection parameter to your queue configuration, and then the queue will interact with the database specified by that connection.

So, in your config/database.php, define a new connection for your queue database:

'connections' => [
    // your existing connections

    'queue' => [
        'driver' => 'mysql',
        'database' => 'your-queue-database',
        // rest of connection information (host, port, etc)
    ],
],

Then, in your config/queue.php, tell your database queue to use your new connection:

'connections' => [
    'database' => [
        'driver' => 'database',
        'connection' => 'queue', // connection name from database config
        'table' => 'jobs',
        'queue' => 'default',
        'retry_after' => 90,
    ],
]

The other option would be to move to another queue driver. Setup redis, sqs, or beanstalk.

Sign up to request clarification or add additional context in comments.

5 Comments

hi, thanks for the answer.. both work, but when i use redis how to see current pending job or failed-job like in database. so i know if there is something wrong or some job not work as expected ? btw, i use laravel forge for server setup.
@martiendt No matter which type of queue you use, failed jobs will be reported to the failed_jobs table in your database when they exceed the max number of attempts allowed by the queue worker.
so when i choose to use redis, i need to setup my queue database too ? ok thanks @patricus i'll try it
Jobs are created as configured, but when listener executes, it connections with default connection always, how to configure dynamic connection for queue listener ?
Why this is not working for me? In my case worker still tries to fetch jobs from default database connection

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.