channel(); $rabbit_channel->queue_declare($queue, false, true, false, false); $callback = function ($msg) use ($queue){ $date_time = date('Y-m-d H:i:s'); $data = $msg->body; Log::info('MQ收到消息[商品状态更新]--->' . $data . '--->' . $date_time . "\n"); $datInfo= json_decode($data, true); if(is_array($datInfo)) { if($datInfo['type'] == 'add_shop') { // 创建群聊 \app\chat\model\ChatGroup::addShop($datInfo['shopId']); }else { $is_log = false; $curl_error = ''; $rand = 'product_update' . Random::build(); $send_id = Base::get_shopping_save_uid($datInfo['shopId'], 'all'); $snd_data =[ 'msg' => '购物车刷新', 'operate_type' => 'reload', 'msg_id' => $rand, 'type' => $datInfo['type'], 'data_type' => 'cart', 'status' => 1 ]; Log::info('推送组'.$send_id.'内容'.json_encode($snd_data)); $snd_data_json = json_encode($snd_data); Gateway::$registerAddress = '127.0.0.1:1238'; $res = Gateway::sendToGroup($send_id, $snd_data_json); Log::info('商品状态更新推送结果-->' . $res); if($is_log) { Db::table('tb_mq_log')->insert([ 'queue' => $queue, 'msg' => $data, 'type' => 'product_update', 'plat' => 'product', 'create_time' => date('Y-m-d H:i:s'), 'fail_time' => date('Y-m-d H:i:s'), 'err_info' => $curl_error, ]); } } } $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); }; $rabbit_channel->basic_consume($queue, '', false, false, false, false, $callback); while ($rabbit_channel->is_consuming()) { Log::info('product.info.change.queue-MQ准备调用wait'); $rabbit_channel->wait(); } $rabbit_channel->close(); $connection->close(); }catch (Exception $exception) { Log::info('product.info.change.queue-MQ错误' . $exception->getMessage() .'----'. $exception->getFile() . '----' . $exception->getLine()); }