--- 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 ```

发表评论 取消回复