---

title: Kafka Connect JDBC Sink 写入 PostgreSQL 实战

keywords: JdbcSinkConnector, auto.create, insert.mode, pk.mode, table.name.format

description: 配置 JDBC Sink 将 Kafka 主题写入 PostgreSQL,启用自动建表、主键与插入模式,实现稳定的数据落库。

tags:

  • JDBC
  • JdbcSinkConnector
  • Kafka
  • auto.create
  • insert.mode
  • pk.mode
  • table.name.format
  • 数据流

categories:

  • 文章资讯
  • 技术教程

---

jdbc-sink.json:

{
  "name": "jdbc-sink-postgres",
  "config": {
    "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
    "tasks.max": "2",
    "topics": "orders",
    "connection.url": "jdbc:postgresql://pg:5432/app",
    "connection.user": "writer",
    "connection.password": "secret",
    "auto.create": "true",
    "auto.evolve": "true",
    "insert.mode": "upsert",
    "pk.mode": "record_key",
    "pk.fields": "id",
    "table.name.format": "public.${topic}",
    "delete.enabled": "false"
  }
}

REST 创建与状态:

curl -X POST -H "Content-Type: application/json" --data @jdbc-sink.json http://localhost:8083/connectors
curl http://localhost:8083/connectors/jdbc-sink-postgres/status

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部