Search code examples
spring-bootspring-batchsolace

Pass data from one writer to another writer after reading from DB


I have to create a batch job where I need to fetch data from 1 DB and after processing dump that data to another DB where auto generated ID would be assigned to persisted data. I need to send that data along with generated ID to solace queue.

Reader(DB1) --data1--> Processor --data2--> Writer (DB2) --data3--> Writer (Solace Publisher)

I am using spring boot-2.2.5.RELEASE and spring-boot-starter-batch.

I have created a job having 1 step that read data from DB1 and write data to DB2 via RepositoryItemReader and RepositoryItemWriter respectively. This is working fine.

Now next task is to send persisted data having generated ID to solace stream (using spring-cloud-starter-stream-solace).

I have below questions. Please assist as I am totally new to spring batch

How can I get the complete record after it's saved to DB2 based on some parameter? Do I have to write my own RepositoryItemWriter having StepExecution Context or can I somehow use the existing RepositoryItemWriter.

Once I got the record I need to use solace stream and there I have publish method which expects argument(record) to be published. I think again I need to write my own Item Writer and either I could use the record passed from above repositoryItemWriter by StepExecutionContext or should I query into DB2 directly from here based on some parameter ?

Either of the above case I need to use stepexecution context but can I use available RepositoryItemWriter or do I have to write my own?

Is there any other concept which is handy in this handy instead of using above approaches?


Solution

  • I have created a job having 1 step that read data from DB1 and write data to DB2 via RepositoryItemReader and RepositoryItemWriter respectively. This is working fine.

    I would add a second step that reads data from the table (in which records have been persisted by step 1 and have their IDs generated) and push it to solace using a custom writer.