diff --git a/config.php b/config.php index e1d2810..e819fe4 100644 --- a/config.php +++ b/config.php @@ -35,8 +35,8 @@ 'minTime'=> 0.0001, //单个job最少执行时间 ], 'topics' => [ - //'autoAckBeforeJobStart' => true, // true 开启; false 关闭;job没跑之前是否直接ack,这样业务代码里面有exit、die等致命错误会丢弃消息,防止消息积压 - ['name'=>'MyJob', 'workerMinNum'=>1, 'workerMaxNum'=>3, 'queueMaxNum'=>10000, 'queueMaxNumForProcess' => 100, 'autoAckBeforeJobStart'=>false], + //'autoAckBeforeJobStart' => true, // true 开启; false 关闭;默认为true,job没跑之前是否直接ack,这样业务代码里面有exit、die等致命错误会丢弃消息,防止消息积压 + ['name'=>'MyJob', 'workerMinNum'=>1, 'workerMaxNum'=>3, 'queueMaxNum'=>10000, 'queueMaxNumForProcess' => 100, 'autoAckBeforeJobStart'=>true], ['name'=> 'MyJob2', 'workerMinNum'=>1, 'workerMaxNum'=>3, 'autoAckBeforeJobStart'=>true], ['name'=> 'MyJob3', 'workerMinNum'=>1, 'workerMaxNum'=>1], ['name'=> 'DefaultClassMethod.test1', 'workerMinNum'=>1, 'workerMaxNum'=>2, 'defaultJobClass'=>'DefaultClassMethod', 'defaultJobMethod'=>'test1'], diff --git a/src/Config.php b/src/Config.php index 6e9e2cd..3946cc0 100644 --- a/src/Config.php +++ b/src/Config.php @@ -1,7 +1,7 @@ * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. @@ -36,11 +36,10 @@ public static function getConfig() * @param mixed $topic * @param mixed $name * */ - public static function getTopicConfig($config, $topic, $name) { $key=array_search($topic, array_column($config, 'name'), true); - return $config[$key][$name] ?? false; + return $config[$key][$name] ?? true; } } diff --git a/src/Jobs.php b/src/Jobs.php index f7a1342..b653c71 100644 --- a/src/Jobs.php +++ b/src/Jobs.php @@ -75,7 +75,7 @@ public function run($topic='') } $this->logger->log('pop data: ' . json_encode($data), 'info'); - $autoAckBeforeJobStart=Config::getTopicConfig($this->config['job']['topics'], $topic, 'autoAckBeforeJobStart'); + $autoAckBeforeJobStart=Config::getTopicConfig($this->config['job']['topics'], $topic, 'autoAckBeforeJobStart') ?? true; if (true === $autoAckBeforeJobStart) { $this->queue->ack(); } diff --git a/src/Jobs/MyJob.php b/src/Jobs/MyJob.php index 31919f7..d4b0442 100644 --- a/src/Jobs/MyJob.php +++ b/src/Jobs/MyJob.php @@ -17,7 +17,7 @@ public static function test1($a, $b) // $client = new \GuzzleHttp\Client(); // $res = $client->request('GET', 'https://www.oschina.net/', ['timeout' => 3]); // echo $res->getStatusCode() . ' test1| title: ' . $a . ' time: ' . $b . PHP_EOL; - die('oh,my gad!'); + die('oh,my gad!').PHP_EOL;//模拟job异常退出,如果设置autoAckBeforeJobStart为false,则消息出队列之后会回到队列,消息不丢失 echo ' test1| title: ' . $a . ' time: ' . $b . PHP_EOL; }