Search code examples
javaspringspring-xd

How Can I prcoess some data and store it to multiple tables through Spring XD Sink


I am using spring xd to get data from a raw table and process it and then store it to multiple tables.

I got success to store in to one tables.

The problem i am facing is how to store data to mutiple tables using Spring XD sink jdbc.

Currently I am creating stream through following code. It will fetch data from raw table(raw_device_data) and after processing it is storing it to sleep_analysis table.

stream create db --definition "source:jdbc --query='select data from raw_device_data where id=330' --url=jdbc:postgresql://localhost:5432/rahar --driverClassName=org.postgresql.Driver --username=postgres --password=root --outputType=application/json | customProcessor15 | sink:jdbc --tableName=sleep_analysis --initializeDatabase=true --columns=latency,sleep_duration,sleep_efficiency,total_minutes_in_bed,total_sleep_time,wakefulness --url=jdbc:postgresql://localhost:5432/rahar --driverClassName=org.postgresql.Driver --username=postgres --password=root"  --deploy

I want to store the processed data to multiple tables.

Thanks.


Solution

  • Send the result to a topic named channel. Create two (or more) streams to consume from that topic - see the documentation.

    foo | bar > topic:result
    
    topic:result > jdbc1
    
    topic:result > jdbc2