我寫了一個處理列表列表的 spring 批處理作業(yè)。Reader 返回列表列表。Processor 處理每個 ListItem 并返回處理過的 List。Writer 從 List of List 向 DB 和 sftp 寫入內(nèi)容。我有一個用例,我從 Spring 批處理器調(diào)用 Async REST api。在 ListenableFuture 響應(yīng)中,我實(shí)現(xiàn)了 LitenableFutureCallback 來處理成功和失敗,它按預(yù)期工作,但在異步調(diào)用返回某些內(nèi)容之前,ItemProcessor 不會等待來自異步 api 的回調(diào)并將對象(列表)返回給編寫器。我不確定如何實(shí)現(xiàn)和處理來自 ItemProcessor 的異步調(diào)用。我確實(shí)讀過 AsyncItemProcessor 和 AsyncItemWriter,但我不確定在這種情況下是否應(yīng)該使用它。我還想過在 AsyncRestTemplate 的 ListenableFuture 響應(yīng)上調(diào)用 get(),但根據(jù)文檔,它會阻塞當(dāng)前線程,直到它收到響應(yīng)。我正在尋求有關(guān)如何實(shí)現(xiàn)這一點(diǎn)的幫助。下面的代碼片段:處理器: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" ); } } } 我原來的批處理作業(yè)是同步的,我正在轉(zhuǎn)換為異步以加快處理速度。我確實(shí)嘗試尋找類似的問題,但找不到足夠的信息。任何指示或幫助都非常感謝。
添加回答
舉報
0/150
提交
取消