将 Kafka Connect 与 Event Streams 配合使用
Kafka Connect 是 Apache Kafka 项目的一部分,允许将外部系统连接到 Kafka。 它包括一个运行时,可运行 连接器 将数据复制到集群或从集群中复制数据。 其主要特征如下:
- 可扩展性:它可以轻松地从一个工人扩展到多个工人。
- 可靠性它能自动管理偏移和连接器的生命周期。
- 可扩展性: 社区为最流行的系统构建的连接器。IBM® 具有用于 MQ 和 Cloud Object Storage 的连接器。
您可以将 Kafka Connect 与 IBM® Event Streams for IBM Cloud® 配合使用,并且可以在 IBM Cloud®内部或外部运行工作程序。IBM 具有 IBM 或社区支持的 50 多个连接器的广泛列表。 您可以在 连接器目录 中找到这些连接器。
Kafka Connect 的运行方式有两种:单机方式和分发方式。 单机方式适用于进行测试以及在系统之间建立临时连接。 分发方式更适用于生产目的。 将 Event Streams 与这两种方式配合使用所需的配置稍有不同。
单机工作程序配置
单机工作程序不使用任何内部主题。 相反,它使用文件来存储偏移量信息。
启动 Kafka Connect 单机工作程序时,必须在所提供的工作程序属性文件中提供引导程序服务器和 SASL 凭证信息。 以下示例列出必须在属性文件中提供的属性:
bootstrap.servers=BOOTSTRAP_ENDPOINTS
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="USER" password="PASSWORD";
security.protocol=SASL_SSL
sasl.mechanism=PLAIN
ssl.protocol=TLSv1.2
ssl.enabled.protocols=TLSv1.2
ssl.endpoint.identification.algorithm=HTTPS
Replace BOOTSTRAP_ENDPOINTS, USER, and PASSWORD with the values from your Event Streams 服务证书 tab in the IBM Cloud console.
源连接器
以下示例列出必须在属性文件中提供的属性:
bootstrap.servers=BOOTSTRAP_ENDPOINTS
producer.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="USER" password="PASSWORD";
producer.security.protocol=SASL_SSL
producer.sasl.mechanism=PLAIN
producer.ssl.protocol=TLSv1.2
producer.ssl.enabled.protocols=TLSv1.2
producer.ssl.endpoint.identification.algorithm=HTTPS
Replace BOOTSTRAP_ENDPOINTS, USER, and PASSWORD with the values from your Event Streams 服务证书 tab in the IBM Cloud console.
接收器连接器
以下示例列出必须在属性文件中提供的属性:
bootstrap.servers=BOOTSTRAP_ENDPOINTS
consumer.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="USER" password="PASSWORD";
consumer.security.protocol=SASL_SSL
consumer.sasl.mechanism=PLAIN
consumer.ssl.protocol=TLSv1.2
consumer.ssl.enabled.protocols=TLSv1.2
consumer.ssl.endpoint.identification.algorithm=HTTPS
Replace BOOTSTRAP_ENDPOINTS, USER, and PASSWORD with the values from your Event Streams 服务证书 tab in the IBM Cloud console.
分发工作程序配置
启动 Kafka Connect 分发工作程序时,必须在所提供的属性文件中提供引导程序服务器和 SASL 凭证信息。 以下示例列出必须在属性文件中提供的属性:
bootstrap.servers=BOOTSTRAP_ENDPOINTS
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="USER" password="PASSWORD";
security.protocol=SASL_SSL
sasl.mechanism=PLAIN
ssl.protocol=TLSv1.2
ssl.enabled.protocols=TLSv1.2
ssl.endpoint.identification.algorithm=HTTPS
Replace BOOTSTRAP_ENDPOINTS, USER, and PASSWORD with the values from your Event Streams 服务证书 tab in the IBM Cloud console.
如果想要使用源连接器,那么还必须为生产者指定 SSL 和 SASL 配置,如下所示:
producer.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="USER" password="PASSWORD";
producer.security.protocol=SASL_SSL
producer.sasl.mechanism=PLAIN
producer.ssl.protocol=TLSv1.2
producer.ssl.enabled.protocols=TLSv1.2
producer.ssl.endpoint.identification.algorithm=HTTPS
如果想要使用接收器连接器,那么还必须为使用者指定 SSL 和 SASL 配置,如下所示:
consumer.sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="USER" password="PASSWORD";
consumer.security.protocol=SASL_SSL
consumer.sasl.mechanism=PLAIN
consumer.ssl.protocol=TLSv1.2
consumer.ssl.enabled.protocols=TLSv1.2
consumer.ssl.endpoint.identification.algorithm=HTTPS
此外,分发方式下的 Kafka Connect 在内部使用三个主题。 如果使用的是 Apache Kafka V0.11 或更高版本中的 Kafka Connect,那么当工作程序启动时会自动创建这些主题。 您提供主题的名称作为配置参数。 请确保具有相同 group.id
配置值的所有工作程序的值相同。
配置 | 描述 |
---|---|
offset.storage.topic |
连接器偏移量主题 |
offset.storage.partitions |
连接器偏移量主题的分区数(缺省值为 25) |
config.storage.topic |
连接器配置主题 |
status.storage.topic |
连接器状态主题 |
status.storage.partitions |
连接器状态主题的分区数(缺省值为 5) |
例如,您可以在属性文件中使用以下键/值对:
offset.storage.topic=connect-offsets
config.storage.topic=connect-configs
status.storage.topic=connect-status
如果只是轻度利用 Kafka Connect,请考虑减少分区数。
有关 Kafka Connect 的更多信息,请参阅 Kafka Connect 概述。