php++think命令报错,think命令行
参考:[https://www.kancloud.cn/uuling/tp5-console/366131](https://www.kancloud.cn/uuling/tp5-console/366131)
```
namespace app\command\consumer\order;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use app\common\tool\Rabbit;
use app\platform\logic\Daraz\Order;
use app\platform\model\PlatformOrder;
class DarazList extends Command
{
protected $input = null;
protected $output = null;
protected $colorList = [
'red'=> "255;0;0;",
'orange'=> "255;165;0;",
'yellow'=> "255;255;0;",
'green'=> "0;255;0;",
'cyan'=> "0;127;255;",
'blue'=> "0;0;255;",
'purple'=> "139;0;255;",
];
protected function info($msg, $color="green"){
# {\033[}为标签起始 {m}为标签结束,属性用数字加分号隔开 38是设置颜色
$colorRGB = isset($this->colorList[$color]) ? $this->colorList[$color] : $this->colorList['green'];
$this->output->writeln("\033[38;2;".$colorRGB."1m".$msg."\033[0m");
}
protected function configure()
{
// 指令配置
$this->setName('DarazList');
// 设置参数
}
protected function execute(Input $input, Output $output)
{
$this->input = $input;
$this->output = $output;
// 指令输出
$this->info('消费者程序启动...');
$this->info('进程pid:' . getmypid());
$queueName = 'daraz_order_list';
dd($queueName);
# 处理失败的队列名
$failedQueueName = 'failed_'.$queueName;
$rabbit = Rabbit::instance('rabbit_mq_sync_task');
# 测试获取单条队列消息
// $data = $rabbit->consumeData($queueName, 5);
// if(!empty($data)){
// // foreach($data as $d){
// // print_r(json_decode(gzuncompress($d['rawData']), true));
// // }
// // $rabbit->ack($data['delivery_tag']);
// dd(json_decode(($data[0]['rawData']), true));
// // dd($data);
// }
// $this->info('结束');
// die;
# 消费计数
$i = 1;
$point = 1000;
$data = [];
$delivery_tag = null;
# 声明对队列消息的业务处理回调
$callback = function($msg) use (&$i, $point, &$data, &$delivery_tag){
if($i%$point == 0){
# 每处理指定数量的队列消息可以标记下逻辑
}
$this->info('第'.$i.'个消息处理');
$delivery_tag = $msg->delivery_info['delivery_tag'];
$rawData = $msg->body;
// $this->info('rawData:'.$i.' '. $rawData .PHP_EOL);
# 业务逻辑处理
$data = json_decode($rawData, true);
unset($rawData);
# 必要参数校验
$accountId = $data['accountId'];
$platformCode = "VO";
$order = $data['order'];
// dd($order);
$orderLogic = new Order();
# 格式化数据
$formatData = $orderLogic->formatOrder($accountId, $platformCode, $order);
// dd($formatData);
// # 入库
$orderModel = new PlatformOrder();
$result = $orderModel->syncOrder($formatData);
# 如果有返回且插入失败,要抛出插入异常
if(!$result){
throw new Exception("PlatformOrder->syncOrder failed", -1);
}
// $msg->delivery_info['channel']->basic_ack($delivery_tag);
$i++;
# 业务逻辑处理完,手动确认删除,否则会一直继续获取队列消息,并标记fetched unacked 只有消费脚本退出进程,才会释放,但不会删除
};
while(true){
try {
$rabbit->consume($callback, $queueName, 0);
}catch(Throwable $e){
# 如果是因为连接关闭,自动重连
if(strpos($e->getMessage(), 'Broken pipe or closed connection') !== false){
$this->info('连接断开,开始重连');
$rabbit->close();
$rabbit->connect();
}
# 异常, 统一丢到失败队列
$this->info('异常记录:'.$e->getMessage());
dd("退出");
$rabbit->ack($delivery_tag);
$failedMsg = [
'raw_queue_name'=> $queueName,
'err_msg'=> $e->getMessage(),
'data'=> $data
];
$failedMsg = json_encode($failedMsg);
$rabbit->easyProduce($failedMsg, $failedQueueName);
$i++;
continue;
}
}
# 常驻进程退出
$this->info('结束');
}
}
```
php++think命令报错,think命令行相关推荐
- linux中make命令报错,Linux命令make报错总结
Linux环境报错原因.解决方法记录(逐步总结) 1:/bin/sh: lex: command not found make[1]: Leaving directory `/home/ksj/tes ...
- linux输入ls命令报错,Linux命令基础2-ls命令
本文介绍的是linux中的ls命令,ls的单词是list files的缩写,意思的列出目录文件. 首先我们在admin用户的当前路径,新建一个test的文件夹,为了方便本文操作和介绍,创建了不同文件类 ...
- idea软件 springboot项目启动报错:命令行太长解决
idea软件 springboot项目启动报错:命令行太长解决 1.找到项目下得.idea文件夹,打开文件workspace.xml 2.搜索标签 <component name="P ...
- 在Linux执行命令报错”Arg list too long”的原因分析
http://www.yunweipai.com/archives/558.html 在Linux执行命令报错"Arg list too long"的原因分析 吞拿鱼手卷 于 3 ...
- linux图形化界面进不去的问题(startx命令报错bash:startx command not found) 经验之谈
1.首先怀疑没安装图形化界面 运行yum groupinstall "X Window System" 如果yum命令报错 出现could not retrieve mirrorl ...
- 解决hexo d命令报错 ERROR Deployer not found: git
解决hexo d命令报错 ERROR Deployer not found: git 问题乍现 探索过程 柳暗花明 完美句号 问题乍现 本来想开开心心搭一个属于自己的博客网站,于是按照网上的教程搭建h ...
- 树莓派(Raspberry Pi 3) centos7使用yum命令报错File /usr/bin/yum, line 30 except KeyboardInterrupt, e:...
使用yum命令报错 File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid ...
- laravel项目运行 php artisan cache:clear 命令报错
laravel项目运行 php artisan cache:clear 命令报错 vscode 项目运行 php artisan cache:clear 命令 出现报错 Failed to clear ...
- yum命令报错在linux下,执行yum命令报错
执行yum命令报错信息如下: [root@webserver ~]# yum list rpmdb: Thread/process 26604/140491933587200 failed: Thre ...
最新文章
- ocr 超时小票识别_【FreeOCR(文字扫描识别软件)和小票打印机测试工具哪个好用】FreeOCR(文字扫描识别软件)和小票打印机测试工具对比-ZOL下载...
- Java判断字符串是否是整数
- kodi 更改服务器文件,云服务器安装kodi
- CentOS6.x下GitLab安装
- [Oracle]Sqlplus 中使用 new_value
- Qt学习之路3---Qt中的坐标系统
- C# 获得Excel工作簿Sheet页面(工作表)集合的名称
- python趣味编程_戏说《西游记》之Python趣味编程:第四回 拜师学艺 破盘中之谜...
- 自定义TextView显示指定行数
- c语言同余法随机数,线性同余法取随机数
- 预约报名小程序 — 预约班车小程序
- Android自定义View,仿QQ显示用户等级
- 台式计算机主板电池型号,台式机主板电池没电会怎么样 主板电池怎么换
- 如何根据函数,绘制出函数的图像
- python简易电话簿系统_Python实现电话簿工具(代码分享)
- chapter3 动态分析基础技术-01在线沙箱 微步云沙箱
- esp8266保存html文件,八,ESP8266 文件保存数据
- 计算机应用基础创新版,计算机应用基础如何培养学生创新意识
- 腾讯再次投资国外著名游戏开发商 入股Epic布局长远
- Gson格式化LocalDateTime