5.2. 自定义现有的 Kamelet 目录
这是自定义现有 kamelet 目录的示例。
目标 :在 Kafka 源 kamelet 中添加 "groupId" 选项。
- 当前版本 kafka source kamelet 包含一个选项 "groupId"。以下示例不包含 "groupId"。
- 在本小节中,您必须将 "groupId" 选项添加到现有 kamelet 目录。
自定义 Kamelet:
获取原始文件。
定义新的 Kamelet 选项
在下面添加有关新选项 "consumerGroup" 的信息
spec: definition: properties:定义的内容类似如下:
consumerGroup: title: Consumer Group description: A string that uniquely identifies the group of consumers to which this source belongs type: string example: "my-group-id"
使用 camel-kafka 组件的 groupId 选项映射新的 kamelet 选项
我们必须定义在以下哪些 camel-kafka 组件选项由 "consumerGroup" 设置:
template: from: parameters:定义的内容如下:
groupId: "\{{?consumerGroup}}"
代码 :
spec: definition: description: Receive data from Kafka topics. properties: ~skip~ consumerGroup: title: Consumer Group description: A string that uniquely identifies the group of consumers to which this source belongs type: string example: "my-group-id" ~skip~ template: from: parameters: allowManualCommit: '{{allowManualCommit}}' autoCommitEnable: '{{autoCommitEnable}}' autoOffsetReset: '{{autoOffsetReset}}' brokers: '{{?bootstrapServers}}' pollOnError: '{{pollOnError}}' saslJaasConfig: org.apache.kafka.common.security.plain.PlainLoginModule required username='{{user}}' password='{{password}}'; saslMechanism: '{{saslMechanism}}' securityProtocol: '{{securityProtocol}}' groupId: "{{?consumerGroup}}" consumersCount: "{{consumersCount}}"