收到队列消息后创建多个文件



我有一个从mongodb读取的项目,并将该信息发送给队列。我的听众从Cloud拾取了队列消息。我能够创建一个.txt文件,该文件输入队列中的所有信息。我一直在搜索的问题是:如何对POJO(Ibusiness1,Ibusiness2,Ibusiness3)内的特定字段进行分类并为每个字段创建文件?以下代码允许我仅创建1个txt文件,并且不整理字段:

    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);
        }

这是我所做的:

pareyportalbean = pojoAuditList = PPB的本地副本

portallist =

    import lombok.Data;
import java.util.List;
@Data
public class PortalList{
    private List<PaymentPortalBean> portalList;
}

回答创建文件:

         for(PaymentPortalBean bean: auditList.getPortalList()) {
                if(bean.RxBusiness().contains( "IBusiness")){
                    File file = new File( exportFilePath );
                    FileWriter writeToFile = new FileWriter( file );
                    String exportFileHeader = CREATE_DTTM|FNAME|LNAME|IBusiness";
                    writeToFile.write( exportFileHeader );
                    writeToFile.write( String.valueOf(bean));
                    writeToFile.flush();
                }

为了找到宜人的效果,我为所需类型创建了另外两个条件语句。运行正常。Mongo DB能够将我需要的字段分开。

相关内容

  • 没有找到相关文章

最新更新