使用 Kafka Connect 搭配 Event Streams

Kafka Connect 是 Apache Kafka 專案的一部分,容許將外部系統連接至 Kafka。 它包含一個運行時,可以運行 連接器 以將資料複製到叢集或從叢集複製資料。 其主要性質如下:

  • 可擴展性:它可以輕鬆地從單一工作人員擴展到多個工作人員。
  • 可靠性:它會自動管理連接器的偏移和生命週期。
  • 延伸: 社群為大部分熱門系統建置連接器。IBM® 具有 MQCloud 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

將 BOOTSTRAP_ENDPOINTS、USER 和 PASSWORD 替換為Event Streams控制台中的IBM Cloud服務憑證標籤中的值。

來源連接器

下列範例列出您必須在內容檔中提供的內容:

    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

將 BOOTSTRAP_ENDPOINTS、USER 和 PASSWORD 替換為Event Streams控制台中的IBM Cloud服務憑證標籤中的值。

接收槽連接器

下列範例列出您必須在內容檔中提供的內容:

    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

將 BOOTSTRAP_ENDPOINTS、USER 和 PASSWORD 替換為Event Streams控制台中的IBM Cloud服務憑證標籤中的值。

分散式工作者節點配置

在您啟動 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

將 BOOTSTRAP_ENDPOINTS、USER 和 PASSWORD 替換為Event Streams控制台中的IBM Cloud服務憑證標籤中的值。

如果您要使用來源連接器,則也必須指定生產者的 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 0.11 版或更新版本中的 Kafka Connect,則這些主題會在工作者節點啟動時自動建立。 請將主題名稱提供為配置參數。 請確保值對於具有相同 group.id 配置值的所有工作者節點都相同。

Kafka Connect 中的主題
配置 說明
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 概觀