如何在 Heroku 中将 Kafka 连接到 Postgres

How to Connect Kafka to Postgres in Heroku

我有一些 Kafka 消费者和生产者 运行 通过我的 Heroku 集群上的 Kafka 实例。我正在寻找创建一个数据接收器连接器以将 Kafka 连接到 PosytgreSQL 以将数据从 Kafka 到我的 heroku PostgreSQL 实例。与 HeroKu docs 非常相似,但有一种方式。

我想不出实现此目标需要采取的步骤。

文档说要查看 Gitlab or Confluence 生态系统页面,但我在其中找不到任何提及 Postgres 的地方。

查看 Confluent Kafka Connectors library 似乎有来自 Debezium 的东西,但我不是 运行 Confluent。

Heroku docs mentions a JDBC connector? I found this Postgres JDBC driver 中的图表,我应该使用这个吗?

如果需要的话,我很乐意创建一个消费者并在数据到来时手动更新 postgres,但我觉得 Kafka 到 Postgres 必须是一个足够通用的接口,应该有一些东西来管理它?

我只是在寻找一些高层次的帮助或例子来让我走上正确的道路。

谢谢

你快到了:)

请记住,Kafka Connect 是 Apache Kafka 的一部分,您可以获得多种连接器。一些(例如 Debezium)是来自 Red Hat 的社区项目,其他(例如 JDBC Sink)是来自 Confluent 的社区项目。

JDBC Sink connector 可让您使用 JDBC 驱动程序将数据从 Kafka 流式传输到数据库 - 例如 Postgres。

这是一个示例配置:


{
    "connector.class"    : "io.confluent.connect.jdbc.JdbcSinkConnector",
    "key.converter"      : "org.apache.kafka.connect.storage.StringConverter",
    "connection.url"     : "jdbc:postgresql://postgres:5432/",
    "connection.user"    : "postgres",
    "connection.password": "postgres",
    "auto.create"        : true,
    "auto.evolve"        : true,
    "insert.mode"        : "upsert",
    "pk.mode"            : "record_key",
    "pk.fields"          : "MESSAGE_KEY"
}

这里有一个 walkthrough 和几个您可能会觉得有用的视频:


Do i actually need to install anything

Kafka Connect 随 Apache Kafka 一起提供。你需要 install the JDBC connector.

Do i actually need to write any code

不,只是配置,类似于我上面引用的内容

can i just call the Connect endpoint , which comes with Kafka,

一旦你installed the connector you run Kafka Connect (a binary that ships with Apache Kafka) and then use the REST endpoint to create the connector using the configuration