Prerequisites
You need PHP 8.5 or later with theswoole, rdkafka, and pcntl extensions. You also need Docker to run Kafka.
Project structure
The sample uses this layout:Install dependencies
Require the framework and the modules package:Source files
Switch between the four source files. Each tab shows the exact file from the sample.- KafkaSampleApplication.php
- MessageFileWriterConsumer.php
- bin/application.php
- composer.json
The single entry point. It points Winter Boot at the
config directory and at the sample namespace.Configuration
Switch between the two config files.application.yml enables the module, and kafka-config.yml defines the bootstrap server and consumer group.
- application.yml
- kafka-config.yml
The full sample file registers See Configuration for every
KafkaModule and sets the server and app identity:application.yml key.Run the app
Create the topic, start the app, send a message, then check the output file. 1. Create the topic:my-topic as soon as the app boots.
3. Send a message:
Next steps
- Read the Kafka module for producer APIs (
KafkaService), consumer tuning, and rdkafka settings. - Browse all Libraries when you need SQS, S3, Redis, or Doctrine in the same app.