多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
recieve.php 参考来源:[https://www.rabbitmq.com/tutorials/tutorial-one-php.html](https://www.rabbitmq.com/tutorials/tutorial-one-php.html) ``` require_once __DIR__ . '/vendor/autoload.php'; use PhpAmqpLib\Connection\AMQPStreamConnection; function reveive(){ $connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest'); $channel = $connection->channel(); // $mq_channel->queue_declare($mq_routing_key, false, true, false, false); // 声明队列 数据持久化 // $exchangeName = 'aliexpress'; //交换机名 $queueName = 'offline_product'; //队列名称 // $routingKey = 'offline_product'; //路由关键字(也可以省略) $channel->queue_declare($queueName, false, true, false, false); try{ echo ' [*] Waiting for messages. To exit press CTRL+C', "\n"; $callback = function($msg) { $runtime = \think\facade\Env::get('RUNTIME_PATH'); $test = $runtime . 'test.txt'; if(!is_file($test)){ file_put_contents($test, '', FILE_APPEND); } $content = " [x] Received ". $msg->body. "\n"; file_put_contents($test, $content, FILE_APPEND); $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); // 这个只能放在外面,放里面如果处理失败了,会呆滞在connect里面 }; $channel->basic_consume($queueName, '', true, false, false, false, $callback); // $consume =$mq_channel->basic_consume($mq_routing_key, '', true, false, false, false, $callback); $channel->wait(); // $channel->is_consuming(); // while($channel->is_consuming()) { // $channel->wait(); // break; // } }catch(\Exception $e){ echo $e->getMessage(); } //关闭连接 $channel->close(); $connection->close(); } ```