easy-batch job writers

The role of easy-batch writers is to write record to sink

Supported data sink

  • With reference to FIG
    from official form

     

     

Notes and tips

  • Process database transactions in JdbcRecordWriter. After each batch, a transaction is created and committed / rolled back.
  • The JpaRecordWriter expects a Java object as input, not a Record. Before passing the record to, make sure to map the record to your domain object type JpaRecordWriter. Process database transactions in JpaRecordWriter. After each batch, a transaction is created and committed / rolled back.
  • The HibernateRecordWriter expects a Java object as input, not a Record. Before passing the record to, make sure to map the record to your domain object type HibernateRecordWriter. The author handles database transactions. After each batch, a transaction is created and committed / rolled back.

Processing data write failure

Sometimes, the data receiver may be temporarily unavailable. In this case, the record writer will not be able to write data, and the job will be aborted. The RetryableRecordWriter can be used to write data to the RetryPolicy using the delegate retry RecordWriter.

 
Job job = new JobBuilder()
    .writer(new RetryableRecordWriter(unreliableDataSinkWriter, new RetryPolicy(5, 1, SECONDS)))
    .build();

This will cause the writer to retry up to 5 times, waiting one second between each attempt. If the data receiver cannot be accessed after 5 attempts, the job will be aborted.

Batch scan

After activation, if an exception occurs during the batch write process, a batch scan will be initiated. Try to write the records one by one as a singleton. In this way, you can skip the wrong record and continue to execute the job instead of failing the entire job in the first failed batch.
This feature is used in conjunction with the transaction writer to successfully execute failed write operations without side effects. However, a known limitation is that when used with non-transactional writers, items may be written twice (for example, in the case of a file writer, the output stream is refreshed before an exception occurs). To avoid this, you should perform a manual rollback operation in the BatchListener # onBatchWritingException method.

References

https://github.com/j-easy/easy-batch/wiki/writers

Guess you like

Origin www.cnblogs.com/rongfengliang/p/12730111.html