我应该在 Spring 批处理流中的哪个位置索引项目?

Where in the Spring Batch flow should I index an item?

我正在从多个平面文件中读取项目,使用一些数据验证步骤处理它们,然后将它们写入 Cassandra。在流程的某处,我还需要向 ElasticSearch 发送索引请求。我想使用 ES Bulk API,因此索引步骤应该在某种程度上进行批处理。

我的问题是,Index 步骤应该是 ItemProcessor 和 ItemWriter,还是完全不同的东西?

我会在 ItemWriter 中进行批量索引,因为它会在一次调用中接收块的所有项目。因此,您将能够在一次操作中批量索引所有项目。 This example is a bit complicated but thewrite method will show you the idea. Alternative you can look in Spring Batch Extensions

我可以使用 unlogged batches

对 Cassandra 做同样的事情

最后,您可以使用 CompositeItemWriter

将多个 ItemWriters(Cassandra 和 Elasticsearch)包装在一个中