Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dispatch a Job to a specific queue in Lumen 5.5

Tags:

php

queue

lumen

In standard a job I use this method to dispatch a Job:

dispatch(new PurchaseJob($trxId, $method, $params));

Next I want to dispatch another Job to send email, but I want to split it to another separate queue. From what I read on Laravel 5.5 docs I could do this:

SendEmailJob::dispatch($userEmail)->onQueue('send_email');

But it does not seems to work on Lumen 5.5.

What could I do to make this work or is there any other method that are not stated in the docs?

like image 279
Ahmad Anshori Avatar asked Oct 09 '17 13:10

Ahmad Anshori


People also ask

What is Dispatch in Laravel queue?

Dispatching jobs to queue using the command bus gives you extra control; you can set the selected connection , queue , and delay from within your job class, decide if the command should be queued or run instantly, send the job through a pipeline before running it, actually you can even handle the whole queueing process ...

What is queue job in Laravel?

Laravel queues provide a unified API across a variety of different queue backends, such as Beanstalk, Amazon SQS, Redis, or even a relational database. Queues allow you to defer the processing of a time consuming task, such as sending an email, until a later time.

What does dispatch do in Laravel?

Dispatcher is a Laravel artisan command scheduling tool used to schedule artisan commands within your project so you don't need to touch the crontab. This sounds brilliant for shared hosts and on-premise apps.

What is queue driver in Laravel?

Laravel Queues Queue Driver Configuration A queue driver is the handler for managing how to run a queued job, identifying whether the jobs succeeded or failed, and trying the job again if configured to do so.

How do I dispatch a job in lumen?

It explains that jobs in Lumen can be dispatched using either the dispatch function or the Queue facade: dispatch(new ExampleJob); Queue::push(new ExampleJob);

Does lumen use Laravel queue jobs?

According to Lumen's documentation on queues, "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."

What is dispatching to a particular queue?

Dispatching To A Particular Queue By pushing jobs to different queues, you may "categorize" your queued jobs and even prioritize how many workers you assign to various queues. Keep in mind, this does not push jobs to different queue "connections" as defined by your queue configuration file, but only to specific queues within a single connection.

How do I push jobs to the queue in lumen?

The default Lumen controller located in app / Http / Controllers / Controller. php uses a DispatchesJob trait. This trait provides several methods allowing you to conveniently push jobs onto the queue, such as the dispatch method: You may also specify the queue a job should be sent to.


1 Answers

I just managed to find a way to dispatch the queue with the specified name in Lumen 5.5.

public function toMail($notifiable)
{
    $job = (new SendFriendRequestEmail($notifiable))->onQueue('email');
    dispatch($job);
}

May be this article will help you understand more

like image 104
Satheesh Narayanan Avatar answered Oct 13 '22 15:10

Satheesh Narayanan