我寫了一個處理列表列表的 spring 批處理作業。Reader 返回列表列表。Processor 處理每個 ListItem 并返回處理過的 List。Writer 從 List of List 向 DB 和 sftp 寫入內容。我有一個用例,我從 Spring 批處理器調用 Async REST api。在 ListenableFuture 響應中,我實現了 LitenableFutureCallback 來處理成功和失敗,它按預期工作,但在異步調用返回某些內容之前,ItemProcessor 不會等待來自異步 api 的回調并將對象(列表)返回給編寫器。我不確定如何實現和處理來自 ItemProcessor 的異步調用。我確實讀過 AsyncItemProcessor 和 AsyncItemWriter,但我不確定在這種情況下是否應該使用它。我還想過在 AsyncRestTemplate 的 ListenableFuture 響應上調用 get(),但根據文檔,它會阻塞當前線程,直到它收到響應。我正在尋求有關如何實現這一點的幫助。下面的代碼片段:處理器:public class MailDocumentProcessor implements ItemProcessor<List<MailingDocsEntity>, List<MailingDocsEntity>> {... Initialization code@Overridepublic List<MailingDocsEntity> process(List<MailingDocsEntity> documentsList) throws Exception { logger.info("Entering MailingDocsEntity processor"); List<MailingDocsEntity> synchronizedList = Collections.synchronizedList(documentsList); for (MailingDocsEntity mailingDocsEntity : synchronizedList) { System.out.println("Reading Mailing id: " + mailingDocsEntity.getMailingId()); ..code to get the file //If the file is not a pdf convert it String fileExtension = readFromSpResponse.getFileExtension(); String fileName = readFromSpResponse.getFileName(); byte[] fileBytes = readFromSpResponse.getByteArray(); try { //Do checks to make sure PDF file is being sent if (!"pdf".equalsIgnoreCase(fileExtension)) { //Only doc, docx and xlsx conversions are supported ...Building REquest object //make async call to pdf conversion service pdfService.convertDocxToPdf(request, mailingDocsEntity); } else { logger.error("The file cannot be converted to a pdf.\n" ); } } } 我原來的批處理作業是同步的,我正在轉換為異步以加快處理速度。我確實嘗試尋找類似的問題,但找不到足夠的信息。任何指示或幫助都非常感謝。
添加回答
舉報
0/150
提交
取消