私はカフカメッセージを消費するPHPアプリケーションを持っています。 カフカに新しいメッセージがあることを知る方法は問題ですか? 最初の解決策は、コンシューマーをPHPで作成し、それをループで実行して新しいメッセージをチェックすることです。このようなものカフカ - 新しいメッセージを見る方法
<?php
namespace MyAppBundle\Command;
use MyAppBundle\EventSourcing\EventSerializer\JSONEventSerializer;
use MyAppBundle\Service\EventProjectorService;
use MyAppBundle\Service\KafkaService;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Exception\RuntimeException;
class EventCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('events:fetch');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var KafkaService $kafkaService */
$kafkaService = $this->getContainer()->get('store_locator.kafka_service');
/** @var EventProjectorService $eventProjector */
$eventProjector = $this->getContainer()->get('store_locator.event_projector');
while(1){
$messages = $kafkaService->fetchEvents();
foreach ($messages as $message) {
$eventProjector->aggregate($message);
}
}
$output->writeln("Finish");
}
}
しかし、私はそれが好きではありません...他の方法はありますか?
良い方法がない場合は、それをどのように実行するのですか?たとえば、何かが失敗したとき。
私は現時点でSymfony/Kafkaソリューションを実際に探しています。カフカのサービスコードを共有する機会はありますか? – nealio82
@Nealio私はあなたが必要とするものは正確にはわかりませんが、 'nmred/kafka-php'パッケージを使用しており、READMEに記載されているようにすべてを実装しています。 – PiotrCh