Hi,
When we dispatch a command, the command bus checks if the command is queue-able. In case it ShoulBeQueued it calls the dispatchToQueue method.
If we define a method named as queue inside our queued command the dispatchToQueue will prefer this method to use for the queuing of the Command.
Here is an example that you can use as a reference:
<?php namespace App\Commands;
use App\Commands\Command;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldBeQueued;
class QueuedCommand extends Command implements ShouldBeQueued {
use InteractsWithQueue, SerializesModels;
public $message;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct($message)
{
$this->message = $message;
}
public function queue($queue, $command)
{
$queue->pushOn('my_queue',$command);
}
}
Now your command will be queued on 'my_queue`. you can work it out using the:
./artisan queue:work --queue="my_queue"
I have tested it using Beanstalkd driver and works perfectly :)
I hope this will help you. Usman.