mirror of https://github.com/dapr/docs.git
3.7 KiB
3.7 KiB
type | title | linkTitle | description | aliases | |
---|---|---|---|---|---|
docs | Kafka binding spec | Kafka | Detailed documentation on the Kafka binding component |
|
Component format
To setup Kafka binding create a component of type bindings.kafka
. See [this guide]({{< ref "howto-bindings.md#1-create-a-binding" >}}) on how to create and apply a binding configuration. For details on using secretKeyRef
, see the guide on [how to reference secrets in components]({{< ref component-secrets.md >}}).
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: kafka-binding
namespace: default
spec:
type: bindings.kafka
version: v1
metadata:
- name: topics # Optional. Used for input bindings.
value: "topic1,topic2"
- name: brokers # Required.
value: "localhost:9092,localhost:9093"
- name: consumerGroup # Optional. Used for input bindings.
value: "group1"
- name: publishTopic # Optional. Used for output bindings.
value: "topic3"
- name: authRequired # Required.
value: "true"
- name: saslUsername # Required if authRequired is `true`.
value: "user"
- name: saslPassword # Required if authRequired is `true`.
secretKeyRef:
name: kafka-secrets
key: saslPasswordSecret
- name: maxMessageBytes # Optional.
value: 1024
Spec metadata fields
Field | Required | Binding support | Details | Example |
---|---|---|---|---|
topics | N | Input | A comma-separated string of topics. | "mytopic1,topic2" |
brokers | Y | Input/Output | A comma-separated string of Kafka brokers. | "localhost:9092,dapr-kafka.myapp.svc.cluster.local:9093" |
consumerGroup | N | Input | A kafka consumer group to listen on. Each record published to a topic is delivered to one consumer within each consumer group subscribed to the topic. | "group1" |
publishTopic | Y | Output | The topic to publish to. | "mytopic" |
authRequired | Y | Input/Output | Enable SASL authentication with the Kafka brokers. | "true" , "false" |
saslUsername | N | Input/Output | The SASL username used for authentication. Only required if authRequired is set to "true" . |
"adminuser" |
saslPassword | N | Input/Output | The SASL password used for authentication. Can be secretKeyRef to use a [secret reference]({{< ref component-secrets.md >}}). Only required if authRequired is set to "true" . |
"" , "KeFg23!" |
maxMessageBytes | N | Input/Output | The maximum size in bytes allowed for a single Kafka message. Defaults to 1024. | 2048 |
Binding support
This component supports both input and output binding interfaces.
This component supports output binding with the following operations:
create
Specifying a partition key
When invoking the Kafka binding, its possible to provide an optional partition key by using the metadata
section in the request body.
The field name is partitionKey
.
Example:
curl -X POST http://localhost:3500/v1.0/bindings/myKafka \
-H "Content-Type: application/json" \
-d '{
"data": {
"message": "Hi"
},
"metadata": {
"partitionKey": "key1"
},
"operation": "create"
}'
Related links
- [Basic schema for a Dapr component]({{< ref component-schema >}})
- [Bindings building block]({{< ref bindings >}})
- [How-To: Trigger application with input binding]({{< ref howto-triggers.md >}})
- [How-To: Use bindings to interface with external resources]({{< ref howto-bindings.md >}})
- [Bindings API reference]({{< ref bindings_api.md >}})