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

49 lines
766 B
PHP

<?php
namespace Kafka;
use Snowflake\Abstracts\BaseObject;
/**
* Class TaskContainer
* @package Kafka
*/
class TaskContainer extends BaseObject
{
private array $_topics = [];
/**
* @param $topic
* @param $handler
*/
public function addConsumer($topic, $handler)
{
if (isset($this->_topics[$topic])) {
return;
}
$this->_topics[$topic] = $handler;
}
/**
* @param $topic
* @param \Kafka\Struct $struct
*/
public function process($topic, Struct $struct)
{
$handler = $this->_topics[$topic] ?? null;
var_dump($handler, $struct);
if (empty($handler)) {
return;
}
call_user_func($handler, $struct);
}
}