Multiple topics to multiple tables
Ingest multiple topics and write to different tables using a single connector instance.
The DataStax Connector allows for mapping multiple topics to multiple tables in a
single connector instance.
Note: Most Apache Kafka™ systems store all messages
in the same format and Kafka Connect workers only support a single converter class for key
and value.
In the example
stocks_topic
, the key
is a basic string and the value is regular JSON.key | value |
---|---|
APPLE |
|
EXXON MOBIL |
|
GENERAL MOTORS |
|
AT&T |
|
FORD MOTOR |
|
And
baseball_topic
has the same structure, basic key and JSON
value.key | value |
---|---|
redsox |
|
redsox |
|
redsox |
|
redsox |
|
redsox |
|
Map the topics into different keyspaces and tables,
stocks_keyspace.stocks_table
and
baseball_keyspace.baseball_table
.
The DataStax Schema definitions:
stocks_table_by_symbol
CREATE TABLE stocks_keyspace.stocks_table_by_symbol ( symbol text, ts timestamp, exchange text, industry text, name text, value double, PRIMARY KEY (symbol, ts));
-
CREATE TABLE baseball_keyspace.baseball_table ( team text primary key, number int, firstname text, lastname text, street text, city text);
In the connector configuration, add the following settings:
"topics”: “stocks_topic,baseball_topic”
stocks_topic
tostocks_table_by_symbol
“topic.stocks_topic.stocks_keyspace.stocks_table_by_symbol.mapping”: “symbol=value.symbol, ts=value.dateTime, exchange=value.exchange, industry=value.industry, name=key.name, value=value.value”
baseball_topic
tobaseball_keyspace.baseball_table
“topic.baseball_topic.baseball_keyspace.baseball_table.mapping”: “team=key, number=value.number, firstname=value.firstname, lastname=value.lastname, street=value.street, city=value.city”