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?
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 ...
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.
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.
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.
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);
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."
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With