The documentation you are viewing is for Dapr v1.1 which is an older version of Dapr. For up-to-date documentation, see the latest version.
Kafka binding spec
Kafka 组件绑定详细说明
配置
要设置 Kafka 绑定,请创建一个类型为 bindings.kafka
的组件。 请参阅本指南,了解如何创建和应用绑定配置。
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: <NAME>
namespace: <NAMESPACE>
spec:
type: bindings.kafka
version: v1
metadata:
- name: topics # Optional. in use for input bindings
value: topic1,topic2
- name: brokers
value: localhost:9092,localhost:9093
- name: consumerGroup
value: group1
- name: publishTopic # Optional. in use for output bindings
value: topic3
- name: authRequired # Required. default: "true"
value: "false"
- name: saslUsername # Optional.
value: "user"
- name: saslPassword # Optional.
value: "password"
- name: maxMessageBytes # Optional.
value: 1024
Warning
以上示例将密钥明文存储, 更推荐的方式是使用 Secret 组件, 这里。元数据字段规范
字段 | 必填 | 绑定支持 | 详情 | 示例 |
---|---|---|---|---|
topics | N | 输入 | A comma separated string of topics | "mytopic1,topic2" |
brokers | Y | Input/Output | A comma separated string of kafka brokers | "localhost:9092,localhost:9093" |
consumerGroup | N | 输入 | A kafka consumer group to listen on | "group1" |
publishTopic | Y | 输出 | The topic to publish to | "mytopic" |
authRequired | Y | Input/Output | Determines whether to use SASL authentication or not. Defaults to "true" |
"true" , "false" |
saslUsername | N | Input/Output | The SASL username for authentication. Only used if authRequired is set to - "true" |
"user" |
saslPassword | N | Input/Output | The SASL password for authentication. Only used if authRequired is set to - "true" |
"password" |
maxMessageBytes | N | Input/Output | The maximum size allowed for a single Kafka message. Defaults to 1024 | 2048 |
绑定支持
此组件支持 输入和输出 绑定接口。
字段名为 ttlInSeconds
。
create
指定分区键
调用 Kafka 绑定时,可以使用请求正文中的 metadata
部分提供可选的分区键。
字段名称为 partitionKey
。
示例:
curl -X POST http://localhost:3500/v1.0/bindings/myKafka \
-H "Content-Type: application/json" \
-d '{
"data": {
"message": "Hi"
},
"metadata": {
"partitionKey": "key1"
},
"operation": "create"
}'
相关链接
Last modified January 1, 0001