改名
This commit is contained in:
+24
-26
@@ -38,7 +38,7 @@ class Kafka extends \Snowflake\Process\Process
|
||||
$config->setTopics($kafka['topics']);
|
||||
|
||||
$this->channel = new Channel(1000);
|
||||
$this->initCoroutine();
|
||||
go([$this, 'listener']);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,35 +59,33 @@ class Kafka extends \Snowflake\Process\Process
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* 监听通道数据传递
|
||||
*/
|
||||
public function initCoroutine()
|
||||
protected function listener()
|
||||
{
|
||||
go(function () {
|
||||
$group = new WaitGroup();
|
||||
while ([$topic, $part, $message] = $this->channel->pop()) {
|
||||
try {
|
||||
$namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer';
|
||||
if (!class_exists($namespace)) {
|
||||
return;
|
||||
}
|
||||
$class = Snowflake::createObject($namespace);
|
||||
if (!($class instanceof ConsumerInterface)) {
|
||||
continue;
|
||||
}
|
||||
$group->add();
|
||||
go(function () use ($group, $class, $topic, $part, $message) {
|
||||
defer(function () use ($group) {
|
||||
$group->done();
|
||||
});
|
||||
$class->onHandler(new Struct($topic, $part, $message));
|
||||
});
|
||||
} catch (\Throwable $exception) {
|
||||
$this->application->error($exception->getMessage());
|
||||
$group = new WaitGroup();
|
||||
while ([$topic, $part, $message] = $this->channel->pop()) {
|
||||
try {
|
||||
$namespace = 'App\\Kafka\\' . ucfirst($topic) . 'Consumer';
|
||||
if (!class_exists($namespace)) {
|
||||
return;
|
||||
}
|
||||
$class = Snowflake::createObject($namespace);
|
||||
if (!($class instanceof ConsumerInterface)) {
|
||||
continue;
|
||||
}
|
||||
$group->add();
|
||||
go(function () use ($group, $class, $topic, $part, $message) {
|
||||
defer(function () use ($group) {
|
||||
$group->done();
|
||||
});
|
||||
$class->onHandler(new Struct($topic, $part, $message));
|
||||
});
|
||||
} catch (\Throwable $exception) {
|
||||
$this->application->error($exception->getMessage());
|
||||
}
|
||||
$group->wait();
|
||||
});
|
||||
}
|
||||
$group->wait();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user