简体   繁体   中英

JDBC Sink Connector -upserting into multiple tables from multiples topics using kafka-connect - Follow up

This is related to the topic mentioned in the below thread

JDBC Sink Connector -upserting into multiple tables from multiples topics using kafka-connect

I know its a bit older post. But my question is also around the same topic. The difference is I want to remove the suffix from the topic name and pass the remaining string as the table name in the sink connector. How can I achieve that?

If it is using SMT, can you please help to achieve that.

Topic Name: Source1-Emp,Source1-Company

Table Name: Emp, Company

Data load needs to happen from multiple topics to multiple tables using a single sink connector.

Can you please help me to implement that.

MUS

You're right in your assumption that this can be done with Single Message Transform (SMT). Here's an example:

curl -X PUT http://localhost:8083/connectors/sink-postgres-00/config \
    -H "Content-Type: application/json" \
    -d '{
        "connector.class": "io.confluent.connect.jdbc.JdbcSinkConnector",
        "connection.url": "jdbc:postgresql://postgres:5432/",
        "connection.user": "postgres",
        "connection.password": "postgres",
        "tasks.max": "1",
        "topics": "Source1-Emp,Source1-Company",
        "auto.create": "true",
        "auto.evolve":"true",
        "transforms":"dropPrefix",
        "transforms.dropPrefix.type":"org.apache.kafka.connect.transforms.RegexRouter",
        "transforms.dropPrefix.regex":"Source1-(.*)$",
        "transforms.dropPrefix.replacement":"$1"
    }'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM