48 lines
865 B
PHP
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
|
|
}
|
|
|
|
|
|
}
|