messageRule = $messageRule; $this->rabbitMqUtil = $rabbitMqUtil; } /** * Execute the console command. * * @return mixed */ public function handle() { $this->line("开始添加发送消息"); $this->messageRule ->where('message_status', 0) ->where('send_time', '<', Carbon::now()->toDateTimeString()) ->whereNotNUll('send_time') ->chunk(100, function($messages){ foreach($messages as $message){ DB::beginTransaction(); try{ $this->rabbitMqUtil->push('add_message_rule', $message); $message->message_status = 1; $message->save(); DB::commit(); Log::info('添加发送消息成功:'.$message->id); }catch (QueryException $exception){ DB::rollBack(); Log::error('添加发送消息:'.$exception->getMessage()); } } }); $this->line("添加发送消息结束"); } }