This commit is contained in:
as2252258@163.com
2021-04-11 18:26:11 +08:00
parent 5b0467944b
commit 8ca36d47d9
4 changed files with 452 additions and 462 deletions
+3 -1
View File
@@ -6,6 +6,7 @@ namespace Annotation;
use Kafka\ConsumerInterface; use Kafka\ConsumerInterface;
use Kafka\TaskContainer; use Kafka\TaskContainer;
use Snowflake\Snowflake;
/** /**
* Class Kafka * Class Kafka
@@ -35,7 +36,8 @@ use Kafka\TaskContainer;
return false; return false;
} }
$container = TaskContainer::getInstance(); /** @var TaskContainer $container */
$container = Snowflake::app()->get('kafka-container');
$container->addConsumer($this->topic, [$handler[0], 'onHandler']); $container->addConsumer($this->topic, [$handler[0], 'onHandler']);
return parent::execute($handler); // TODO: Change the autogenerated stub return parent::execute($handler); // TODO: Change the autogenerated stub
+2 -1
View File
@@ -68,7 +68,8 @@ class OnPipeMessage extends Callback
{ {
[$topic, $message] = $message['body']; [$topic, $message] = $message['body'];
$container = TaskContainer::getInstance(); /** @var TaskContainer $container */
$container = Snowflake::app()->get('kafka-container');
$container->process($topic, new Struct($topic, $message)); $container->process($topic, new Struct($topic, $message));
return 'success'; return 'success';
} }
-15
View File
@@ -18,21 +18,6 @@ class TaskContainer extends BaseObject
private array $_topics = []; private array $_topics = [];
private static ?TaskContainer $container = null;
/**
* @return \Kafka\TaskContainer
*/
public static function getInstance(): TaskContainer
{
if (!(static::$container instanceof TaskContainer)) {
static::$container = new TaskContainer();
}
return static::$container;
}
/** /**
* @param $topic * @param $topic
* @param $handler * @param $handler
+2
View File
@@ -26,6 +26,7 @@ use HttpServer\Shutdown;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use Kafka\Producer; use Kafka\Producer;
use Annotation\Annotation as SAnnotation; use Annotation\Annotation as SAnnotation;
use Kafka\TaskContainer;
use ReflectionException; use ReflectionException;
use Snowflake\Aop; use Snowflake\Aop;
use Snowflake\Async; use Snowflake\Async;
@@ -487,6 +488,7 @@ abstract class BaseApplication extends Service
'aop' => ['class' => Aop::class], 'aop' => ['class' => Aop::class],
'jwt' => ['class' => Jwt::class], 'jwt' => ['class' => Jwt::class],
'async' => ['class' => Async::class], 'async' => ['class' => Async::class],
'kafka-container' => ['class' => TaskContainer::class],
'filter' => ['class' => HttpFilter::class], 'filter' => ['class' => HttpFilter::class],
'goto' => ['class' => BaseGoto::class], 'goto' => ['class' => BaseGoto::class],
'channel' => ['class' => Channel::class], 'channel' => ['class' => Channel::class],