Skip to main content
In this guide, you will learn how to connect your Restate service handler to a Kafka topic. Restate lets you connect any handler to a Kafka topic, and invoke the handler for each event that arrives on the topic. This way, you can use Restate to process events in a lightweight, flexible, transactional way.
1

Get the Greeter service template and run the service

You can choose any of the SDK languages for this quickstart. You do not need to adapt the handler code to be able to read from Kafka. Any handler can be connected to Kafka.
2

Running Restate Server

Start the Restate Server:
3

Register the service

Let the Restate Server know about the Greeter service by registering it:
4

Start Kafka and the Kafka ingress integration

Let’s start a Kafka cluster with a single broker, create a topic named greetings, and run the Kafka ingress integration next to it.You can run your Kafka cluster in your preferred way. Here, we will use Docker Compose.Create a docker-compose.yaml file with the following content:
docker-compose.yaml
The restate-kafka-integration container consumes the greetings topic and invokes Greeter/greet for each record. It reaches the Restate Server running on your machine via host.docker.internal.Start the containers:
5

Invoke the handler by publishing an event

Create a Kafka producer and publish an event to the greetings topic:
Then type a message and press enter. The greeter takes a String name as an input:
For some greeter templates, you might need to send just the name as "Sarah".
6

We invoked a Restate service over Kafka

You now see your handler getting invoked.The way this worked is that the Kafka ingress integration consumed the record from the topic and sent it to Restate, which durably persisted it, similar to what it does for HTTP invocations.It then pushed the message to the handler, as opposed to the pull mechanism that you would have with a Kafka consumer.If the handler fails, Restate will retry the request until it eventually succeeds.Have a look at the Kafka ingress integration docs to learn how to map Kafka records to Restate invocations, connect to secured clusters, and read record metadata in your handler. Have a look at the Event Processing use case page to learn about what you can do with Restate and event processing.