doc:新增异常说明

This commit is contained in:
zyimm 2023-07-10 09:52:03 +08:00
parent 8630b53f8d
commit c3c6bfd3b7
3 changed files with 24 additions and 9 deletions

View File

@ -3,7 +3,9 @@
namespace tm\xls\rocketMq\thinkphp\consumer;
use React\EventLoop\Loop;
use tm\xls\rocketMq\thinkphp\consumer\contract\ListenerInterface;
use tm\xls\rocketMq\thinkphp\consumer\message\Message;
use tm\xls\rocketMq\thinkphp\exception\ConsumerException;
class Consumer
{
@ -29,14 +31,18 @@ class Consumer
$loop = Loop::get();
$key = $this->message->getTopic().$this->message->getTag();
$subscribes = $this->getSubscribe()[$key] ?? [];
foreach ($subscribes as $subscribe){
$loop->addTimer(0, function () use ($subscribe){
foreach ($subscribes as $subscribe) {
$loop->addTimer(0, function () use ($subscribe) {
$handler = app()->make($subscribe, [
$this->message
]);
if($handler->enable()){
if ($handler instanceof ListenerInterface) {
if ($handler->enable()) {
$handler->handle();
}
} else {
throw new ConsumerException('Consumer needs to implement ListenerInterface');
}
});
}
$loop->run();
@ -47,7 +53,7 @@ class Consumer
*
* @return array
*/
private function getSubscribe():array
private function getSubscribe(): array
{
return config('rocket_mq.subscribe');
}

View File

@ -0,0 +1,10 @@
<?php
namespace tm\xls\rocketMq\thinkphp\exception;
use Exception;
class ConsumerException extends Exception
{
}

View File

@ -49,7 +49,6 @@ class Producer
//todo 失败
},
]);
$promise = $pool->promise();
$promise->wait();
}