Each event leads to an invocation, meaning a request to execute a handler. Each invocation has its own unique ID and lifecycle.
Have a look at managing invocations to learn how to manage the lifecycle of an invocation.
Invoking Handlers via Kafka Events
You can invoke handlers via Kafka events, by doing the following:1
Develop and register an event handler
You can invoke any handler via Kafka events.
The event payload will be (de)serialized as JSON.
- When invoking Virtual Object or Workflow handlers via Kafka, the key of the Kafka record will be used to determine the Virtual Object/Workflow key. The key needs to be a valid UTF-8 string. The events are delivered to the subscribed handler in the order in which they arrived on the topic partition.
- When invoking Virtual Object or Workflow shared handlers via Kafka, the key of the Kafka record will be used to determine the Virtual Object/Workflow key. The key needs to be a valid UTF-8 string. The events are delivered to the subscribed handler in parallel without ordering guarantees.
- When invoking Service handlers over Kafka, events are delivered in parallel without ordering guarantees.
2
Configure Restate to connect to a Kafka cluster
Define the Kafka cluster that Restate needs to connect to in the Restate configuration file:And make sure the Restate Server uses it via
restate.toml
restate-server --config-file restate.toml
.Check the configuration docs for more details.Configuring Kafka clusters via environment variables
Configuring Kafka clusters via environment variables
You can also configure the Kafka clusters via the
RESTATE_INGRESS__KAFKA_CLUSTERS
environment variable:3
Register the service you want to invoke.
4
Subscribe the event handler to the Kafka topic
Let Restate forward events from the Kafka topic to the event handler by creating a subscription:Once you’ve created a subscription, Restate immediately starts consuming events from Kafka.
The handler will be invoked for each event received from Kafka.The
options
field is optional and accepts any configuration parameter from librdkafka configuration.Kafka connection configuration
Kafka connection configuration
You can pass arbitrary Kafka cluster options in the For the full list of options, check librdkafka configuration.
restate.toml
, and those options will be applied for all the subscriptions to that cluster, for example:restate.toml
Multiple Kafka clusters support
Multiple Kafka clusters support
You can configure multiple kafka clusters in the And then, when creating the subscriptions, you refer to the specific cluster by
restate.toml
file:restate.toml
name
:Event metadata
Event metadata
You can access the event metadata in the handler by getting the request headers map:Each event carries within this map the following entries:
restate.subscription.id
: The subscription identifier, as shown by the Admin API.kafka.offset
: The record offset.kafka.partition
: The record partition.kafka.timestamp
: The record timestamp.
Raw event support
Raw event support
Check out the serialization documentation of your SDK to learn how to receive raw events in your handler.
Managing Kafka Subscriptions
Restate can trigger handlers via Kafka events.Create Subscriptions
Subscribe a handler to a Kafka topic:options
field is optional and accepts any librdkafka configuration parameter.
List Subscriptions
View current subscriptions:Delete Subscriptions
Remove a subscription using its ID (starts withsub_
):