Files
kiri-core/Annotation/Kafka.php
T
as2252258@163.com 8ca36d47d9 modify
2021-04-11 18:26:11 +08:00

48 lines
865 B
PHP

<?php
namespace Annotation;
use Kafka\ConsumerInterface;
use Kafka\TaskContainer;
use Snowflake\Snowflake;
/**
* Class Kafka
* @package Annotation
*/
#[\Attribute(\Attribute::TARGET_CLASS)] class Kafka extends Attribute
{
/**
* Kafka constructor.
* @param string $topic
*/
public function __construct(public string $topic)
{
}
/**
* @param array $handler
* @return mixed
*/
public function execute(array $handler): mixed
{
if (!($handler[0] instanceof ConsumerInterface)) {
return false;
}
/** @var TaskContainer $container */
$container = Snowflake::app()->get('kafka-container');
$container->addConsumer($this->topic, [$handler[0], 'onHandler']);
return parent::execute($handler); // TODO: Change the autogenerated stub
}
}