I have a project that reads from mongodb and sends that information to the queue. my listener picks up the queue message from cloud. I am able to create a .txt file that inputs all the information inside from the queue. My problem that I have been searching for is: How can I sort through a specific field inside the POJO (IBusiness1,IBusiness2,IBusiness3)and create the file for each? The following code allows me to create only 1 txt file and it does not sort the field:
public static void main(String[] args) {
SpringApplication.run(PaymentPortalBatchListenerApplication.class, args);
}
private class MessageHandler implements IMessageHandler {
private final Logger logger = LoggerFactory.getLogger(MessageHandler.class);
public CompletableFuture<Void> onMessageAsync(IMessage message) {
System.out.println("received "+message.getBody());
ObjectMapper om = new ObjectMapper();
PortalList auditList = null;
try {
auditList = om.readValue( message.getBody(), PortalList.class );
System.out.println( "**Audit Message " + auditList );
logger.info( "Creating file");
String exportFilePath = "C:\\filewriter\\IBusiness1 " +
LocalDateTime.now().format(formatter) + ".txt";
File file = new File(exportFilePath);
FileWriter writeToFile = new FileWriter(file);
String exportFileHeader = "CREATE_DTTM|FNAME|LNAME|IBusiness";
StringHeaderWriter headerWriter = new
StringHeaderWriter(exportFileHeader);
writeToFile.write(exportFileHeader);
writeToFile.write( String.valueOf( headerWriter));
writeToFile.write( String.valueOf(auditList));
writeToFile.flush();
} catch (IOException e) {
e.printStackTrace();
}
// System.out.println(auditList);
return CompletableFuture.completedFuture(null);
}