Skip to main content
Build a consumer app that reads from a Kafka topic and writes every message to a file. You use Winter Boot for the application runtime and the Winter Kafka module from Winter Modules for topic access. You test the whole flow locally with a single-broker Kafka running in Docker.

Prerequisites

You need PHP 8.5 or later with the swoole, rdkafka, and pcntl extensions. You also need Docker to run Kafka.
Start a single-broker Kafka before you run the app:

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.
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.
The full sample file registers KafkaModule and sets the server and app identity:
See Configuration for every application.yml key.

Run the app

Create the topic, start the app, send a message, then check the output file. 1. Create the topic:
2. Start the application:
The Kafka worker starts polling my-topic as soon as the app boots. 3. Send a message:
4. Verify consumption:
You see one line per consumed message, for example:

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.