Kafka events
To handle Kafka eventsΒ , extend the KafkaHandler class:
use Bref\Context\Context;
use Bref\Event\Kafka\KafkaEvent;
use Bref\Event\Kafka\KafkaHandler;
class MyHandler extends KafkaHandler
{
public function handleKafka(KafkaEvent $event, Context $context): void
{
foreach ($event->getRecords() as $record) {
$data = $record->getValue();
// do something
}
}
}Then, create a Lambda function that listens to a Kafka topic with the handler you created. Here is an example with Amazon MSK (Managed Streaming for Apache Kafka):
Laravel
serverless.yml
functions:
# ...
worker:
handler: App\MyHandler
runtime: php-84
events:
- msk:
arn: arn:aws:kafka:eu-west-1:111111111111:cluster/my-cluster/xxxx-xxxx-xxxx
topic: my-topicThe App\MyHandler class will be instantiated by Laravelβs service container.
For a self-managed Kafka cluster, use the kafka event instead. Learn more about the msk event and the kafka event in the Serverless Framework documentation.
Last updated on