JDBC Source Connector能否使用静态目标Topic名替代源表名?
Absolutely! You can completely bypass the auto-generated topic names (built from topic.prefix + source table name) and define static, custom topic names for each of your tables using the JDBC Source Connector's configuration options. Here's how to make it work:
Key Configuration Properties
The core property you’ll use is topic.map, which lets you explicitly map each source table to a desired Kafka topic name. Pair this with either table.whitelist (for exact table matches) or table.inclusion.regex (for regex-based table selection) to specify which tables the connector should process.
Example Configuration
Suppose you have a source table named users$public (with the special $ character) and want to send its data to a clean Kafka topic called blah-users-public. Your connector config would look like this:
name=jdbc-source-custom-topics connector.class=io.confluent.connect.jdbc.JdbcSourceConnector tasks.max=1 connection.url=jdbc:your-database-url-here connection.user=your-username connection.password=your-password mode=incrementing incrementing.column.name=id table.whitelist=users$public topic.map=users$public:blah-users-public
How It Works
table.whitelisttells the connector to only process theusers$publictable.topic.mapoverrides the default naming logic: instead of creatingblah-users$public(fromtopic.prefix+ table name), it uses your explicitly definedblah-users-publictopic.
Additional Tips
- If you’re using
topic.map, you don’t need thetopic.prefixproperty anymore—since you’re defining topics directly. - For multiple tables, add more entries to
topic.mapseparated by commas:table.whitelist=users$public,orders$private topic.map=users$public:blah-users-public,orders$private:blah-orders-private - Ensure target Kafka topics exist already, or enable
auto.create.topics.enableon your cluster (though explicit topic creation is recommended for production). - If using regex to match tables (via
table.inclusion.regex), note thattopic.mapstill requires exact table-to-topic mappings—regex isn’t supported in the map itself.
Content of the question originates from Stack Exchange, asked by Sahas

