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: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.
Register the Kafka cluster in Restate
Register the Kafka cluster that Restate needs to connect to, using the Restate CLI:You can pass any librdkafka configuration parameter as additional
key=value arguments.
Alternatively, you can read the properties from a file with -f my-cluster.properties, or open an editor on a properties template with --edit.Using SASL/SSL (e.g. Confluent Kafka)
Using SASL/SSL (e.g. Confluent Kafka)
To connect to a Kafka cluster that requires SASL/SSL authentication (e.g., Confluent Kafka), you can specify the necessary parameters when registering the cluster:For Confluent Cloud, you can copy the client configuration properties from the Confluent Cloud console into a properties file and register the cluster with it:
Using SASL OAuth2.0 / OpenID Connect
Using SASL OAuth2.0 / OpenID Connect
The Kafka ingress supports SASL OAUTHBEARER authentication, enabling OAuth 2.0/OpenID Connect (OIDC) token-based connections to managed Kafka services.Configure SASL OAUTHBEARER via the cluster properties. These options are passed directly to librdkafka.Example for Confluent Cloud:Common OAUTHBEARER options:
For the full list of available options, see the librdkafka CONFIGURATION.md.
| Option | Description |
|---|---|
security.protocol | Set to SASL_SSL for encrypted connections |
sasl.mechanism | Set to OAUTHBEARER |
sasl.oauthbearer.method | Set to oidc for OIDC-based token retrieval |
sasl.oauthbearer.client.id | OAuth client ID |
sasl.oauthbearer.client.secret | OAuth client secret |
sasl.oauthbearer.token.endpoint.url | OAuth token endpoint URL |
sasl.oauthbearer.scope | OAuth scope (if required by provider) |
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 trailing
key=value options are optional and accept any configuration parameter from librdkafka configuration.Kafka connection configuration
Kafka connection configuration
You can pass arbitrary Kafka cluster properties when registering the cluster, and those properties will be applied for all the subscriptions to that cluster, for example:For the full list of options, check librdkafka configuration.
Multiple Kafka clusters support
Multiple Kafka clusters support
You can register multiple Kafka clusters:And then, when creating the subscriptions, you refer to the specific cluster by 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 byrestate subscriptions list.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 Clusters
Manage the registered Kafka clusters with therestate kafka-clusters CLI commands (alias kc):
Managing Kafka Subscriptions
Manage the subscriptions with therestate subscriptions CLI commands (alias sub):