Apache camel 同时处理两个 csv 文件

2022-01-19 00:00:00 java apache-camel

我正在尝试处理两个 .csv 文件并将它们的数据保存到数据库中.我使用的是 java dsl 而不是 springs.

I am trying to process two .csv files and to persist their data to the database. I am using java dsl and not springs for the same.

为了更好地解释这个场景:
我正在读取两个 .csv 文件并处理它们以将它们的数据上传到 sql 数据库中.我为此执行的步骤是

To explain the scenario a bit better :
I am reading two .csv files and processing them to upload their data in the sql database.The steps I performed for this are

  1. 在 servlet 容器文件中指定引擎初始化程序.
  2. 创建一个EngineInitialiser
  3. 将 EngineInitialiser 绑定到核心引擎.
  4. 创建将数据持久保存到数据库所需的 dao 文件.
  5. 创建定义绑定的引擎模块.
  6. 定义用于定义文件特定格式的文件.

但是问题是

尝试将交换解组为 BindyCsvDataFormat 时出现问题.有两个格式类文件,因为我为 file1 输入文件指定了一个,为 file2.csv 指定了一个.

There is a problem when trying to unmarshal the exchange to a BindyCsvDataFormat. There are two format class files as I have specified one for the file1 input file and one for the file2.csv.

现在 bindy 正在尝试将格式映射到父类文件.但是,当它获取 file1.csv 时,它会将其映射到同一包下定义的模型 1 和模型 2.但是,它应该只映射到一个类.如何强制它只映射到一个格式类?

错误如下:

Now bindy is trying to map the format to the parent class file .However, when it picks up the file1.csv it maps it to both the model1 and model2 defined under the same package. However, it should map it to only one class .How do I force it to map to only one format class?

The error is as follows:

java.lang.IllegalArgumentException:缺少某些字段(可选或必填),行:1在 org.apache.camel.dataformat.bindy.BindyCsvFactory.bind(BindyCsvFactory.java:215)atorg.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.unmarshal(BindyCsvDataFormat.java:169)atorg.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:58)在 org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)在 org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)在 org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)在 org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)在 org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71) 在 org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) 在 org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99) 在 org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)在 org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)在 org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)在 org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:333)在 org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:223)在 org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)在 org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)在 org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:304)在 org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)在 org.apache.camel.processor.Pipeline.process(Pipeline.java:117)在 org.apache.camel.processor.Pipeline.process(Pipeline.java:80)在 org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)在 org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)在 org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)在 org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)在 org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:50)在 org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)在 org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)在 org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)在 org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)在 org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)在 org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:352)在 org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:175)在 org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:136)在 org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:138)在 org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:90)在 java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)在 java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)在 java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)在 java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)在 java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)在 java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)在 java.lang.Thread.run(Thread.java:619)|#]

java.lang.IllegalArgumentException: Some fields are missing (optional or mandatory), line: 1 at org.apache.camel.dataformat.bindy.BindyCsvFactory.bind(BindyCsvFactory.java:215) atorg.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.unmarshal(BindyCsvDataFormat.java:169)atorg.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:58) at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:333) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:223) at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:304) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) at org.apache.camel.processor.Pipeline.process(Pipeline.java:117) at org.apache.camel.processor.Pipeline.process(Pipeline.java:80) at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150) at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117) at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:50) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99) at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90) at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71) at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:352) at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:175) at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:136) at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:138) at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:90) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317) at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:619) |#]

推荐答案

不同的实体管理器应该解决问题.

Different entity managers should solve the problem.

相关文章