Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Use different queue connection to dispatch Jobs

I am using laravel 5.1 and i am using the dispatch method to push the job onto the queue. But there are two kind of jobs and i have created and two queues for that in sqs. How should i achieve this?

like image 248
Sameer Sheikh Avatar asked Jan 08 '16 11:01

Sameer Sheikh


People also ask

How do I start the queue worker using the command line in Laravel?

Queue Workers on a Live Server After the configuration files are created, you'll need to activate the supervisor using the following commands: sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl start laravel-worker:*

Are Laravel jobs asynchronous?

php - Laravel Jobs are not asynchronous - Stack Overflow. Stack Overflow for Teams – Start collaborating and sharing organizational knowledge.

What is the difference between job and queue in Laravel?

Jobs and QueuesThe line itself is the Queue, and each customer in the line is a Job. In order to process Jobs in the Queue you need command line processes or daemons. Think of launching a queue daemon on the command line as adding a new bank teller to the pool of available bank tellers.


3 Answers

In order to specify the queue you need to call onQueue() method on your job object, e.g.:

$job = (new SendReminderEmail($user))->onQueue('emails');
$this->dispatch($job);

If you want to send the job to a connection other than default, you need to do fetch connection manually and send the job there:

$connection = Queue::connection('connection_name');
$connection->pushOn('queue_name', $job)
like image 74
jedrzej.kurylo Avatar answered Sep 24 '22 02:09

jedrzej.kurylo


This worked for me.

//code to be used in the controller (taken from @jedrzej.kurylo above)
$job = (new SendReminderEmail($user))->onQueue('emails');
$this->dispatch($job);

I think this dispatches the job on to the queue named "emails". To execute the job dispatched on 'emails' queue:

//Run this command in a new terminal window
php artisan queue:listen --queue=emails
like image 27
agent47 Avatar answered Sep 23 '22 02:09

agent47


I'd suggest this:

app('queue')->connection('connection_name')->pushOn('queue_name', $job);

From here: In Laravel how to create a queue object and set their connection without Facade

like image 34
markashworth Avatar answered Sep 22 '22 02:09

markashworth