Kafka binding spec

Detailed documentation on the Kafka binding component

Component format

To setup Kafka binding create a component of type bindings.kafka. See this guide on how to create and apply a binding configuration.

  1. apiVersion: dapr.io/v1alpha1
  2. kind: Component
  3. metadata:
  4. name: <NAME>
  5. namespace: <NAMESPACE>
  6. spec:
  7. type: bindings.kafka
  8. version: v1
  9. metadata:
  10. - name: topics # Optional. in use for input bindings
  11. value: topic1,topic2
  12. - name: brokers
  13. value: localhost:9092,localhost:9093
  14. - name: consumerGroup
  15. value: group1
  16. - name: publishTopic # Optional. in use for output bindings
  17. value: topic3
  18. - name: authRequired # Required. default: "true"
  19. value: "false"
  20. - name: saslUsername # Optional.
  21. value: "user"
  22. - name: saslPassword # Optional.
  23. value: "password"
  24. - name: maxMessageBytes # Optional.
  25. value: 1024

Warning

The above example uses secrets as plain strings. It is recommended to use a secret store for the secrets as described here.

Spec metadata fields

FieldRequiredBinding supportDetailsExample
topicsNInputA comma separated string of topics“mytopic1,topic2”
brokersYInput/OutputA comma separated string of kafka brokers“localhost:9092,localhost:9093”
consumerGroupNInputA kafka consumer group to listen on“group1”
publishTopicYOutputThe topic to publish to“mytopic”
authRequiredYInput/OutputDetermines whether to use SASL authentication or not. Defaults to “true”“true”, “false”
saslUsernameNInput/OutputThe SASL username for authentication. Only used if authRequired is set to - “true”“user”
saslPasswordNInput/OutputThe SASL password for authentication. Only used if authRequired is set to - “true”“password”
maxMessageBytesNInput/OutputThe maximum size allowed for a single Kafka message. Defaults to 10242048

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:

  1. curl -X POST http://localhost:3500/v1.0/bindings/myKafka \
  2. -H "Content-Type: application/json" \
  3. -d '{
  4. "data": {
  5. "message": "Hi"
  6. },
  7. "metadata": {
  8. "partitionKey": "key1"
  9. },
  10. "operation": "create"
  11. }'

Related links

Last modified March 18, 2021: Merge pull request #1321 from dapr/aacrawfi/logos (9a399d5)