在以上的推送中,有时候不仅仅只是推送短信,也有可能推送邮件等,那么think-queue怎么进行多任务处理呢?
生产者代码
<?php
namespace app\client\controller;
use GuzzleHttp\Client;
use think\facade\Request;
use think\Queue;
class Produce
public function releaseTaskQueue()
$deal_type = Request::instance()->get('deal_type');
switch ($deal_type){
case 'send_sms' :
$content = ['timestamp' => time(),'random_str' => uniqid(),'task_name' => 'task_a'];
Queue::push('app\client\controller\Consume@send_sms',$content,'SendJob');
break;
case 'send_email' :
$content = ['timestamp' => time(),'random_str' => uniqid(),'task_name' => 'task_b'];
Queue::push('app\client\controller\Consume@send_email',$content,'SendJob');
break;
消费者代码
<?php
namespace app\client\controller;
use GuzzleHttp\Client;
use think\queue\Job;
class Consume
public function send_sms(Job $job, $data)
print '发送短信中'.PHP_EOL;
public function send_email(Job $job, $data)
print '发送邮件中'.PHP_EOL;
只需要使用 任务类名@方法名
就可以了