我试图将NULL或Empty消息路由到系统上的本地存档,并处理具有内容的文件。使用Camel 2.17,Jboss Fuse servicemix捆绑包。我无法使其正常工作。这一定是我做错了。我尝试了下面看到的一些不同的事情(所有评论)。
尝试的示例:
} else if (Boolean.parseBoolean(isCompressedOnly)) { //Only Zipped or Compressed
// .when(simple("${file:length} == 0"))
// .when(simple("${header.CamelFileLength} == 0" ))
// .when(header("CamelFileLength").isEqualTo(0))
// .when(body().isNull())
// .when(header("CamelFileLength").isEqualTo(0))
// .when(simple("${header.CamelFileLength} < 10" ))
// .when(simple("${header.CamelFileLength} &eq; 0" ))
// .when(simple("${file:length} == null"))
ZipFileDataFormat zipFile = new ZipFileDataFormat();
zipFile.setUsingIterator(true);
from(fromStr)
.routeId("Zipped.Only")
.log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
.unmarshal(zipFile)
.split(body(Iterator.class))
.streaming()
.convertBodyTo(String.class)
.choice()
.when(simple("${file:length} == null"))
.wireTap("file" + errorArchive)
.log(LoggingLevel.INFO,"File Size: ${header.CamelFileLength}, File is Empty or Zero Length!")
.endChoice()
.otherwise()
.wireTap("file:" + fileArchive)
.split(body().tokenize("\n"), new FleetAggregationStrategy()).streaming()
.process(new EndpointParametersProcessor(decoderName))
.end()
.to(toStr);
} else {
唯一可行的语句(因为所有消息都会路由到空文件端点,即使它们具有长度/大小/数据/内容)
.when(simple("${header.CamelFileLength} < 10" ))
你能告诉我我在做什么错吗?谢谢!
在哪里可以找到与Header相关的方法?例如
.when(header(“ result”)。isEqualTo(“ A”)
.to(routeA)
我尝试不嵌套choice(),但是所有内容都通过第一个when()路由。
ZipFileDataFormat zipFile = new ZipFileDataFormat();
zipFile.setUsingIterator(true);
from(fromStr)
.routeId("Zipped.Only")
.log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
.unmarshal(zipFile)
.split(body(Iterator.class))
.streaming()
.convertBodyTo(String.class)
.choice()
.when(simple("${header.CamelFileLength} < 10" ))
.wireTap("file:" + errorArchive)
.log(LoggingLevel.INFO,"File Size: ${header.CamelFileLength}, File is Empty or Zero Length!")
.endChoice()
.when(simple("${header.CamelFileLength} > 10" ))
.wireTap("file:" + fileArchive)
.split(body().tokenize("\n"), new FleetAggregationStrategy()).streaming()
.process(new EndpointParametersProcessor(decoderName))
.end()
.to(toStr)
.endChoice()
.end();
├── [drwxr-xr-x 4.0K] core
│ ├── [drwxr-xr-x 4.0K] enriched
│ ├── [drwxr-xr-x 4.0K] mt1
│ │ └── [drwxr-xr-x 4.0K] processed
│ ├── [drwxr-xr-x 4.0K] mt2
│ │ └── [drwxr-xr-x 4.0K] processed
│ ├── [drwxr-xr-x 4.0K] mt3
│ │ └── [drwxr-xr-x 4.0K] processed
│ └── [drwxr-xr-x 4.0K] tobeprocessed
├── [drwxr-xr-x 4.0K] dbase
├── [drwxr-xr-x 4.0K] fleet
│ └── [drwxr-xr-x 4.0K] core
│ ├── [drwxr-xr-x 4.0K] archive
│ └── [drwxr-xr-x 4.0K] error
│ ├── [-rw-r--r-- 0] GCMS_20190420-0815.csv
│ ├── [-rw-r--r-- 0] GCMS_20190420-0816.csv
│ ├── [-rw-r--r-- 0] GCMS_20190420-0817.csv
│ ├── [-rw-r--r-- 1.1M] GCMS_20190420-0945.csv
│ ├── [-rw-r--r-- 1.1M] GCMS_20190420-0953.csv
│ └── [-rw-r--r-- 1.1M] GCMS_20190420-1001.csv
└── [drwxr-xr-x 4.0K] upload
克劳斯,我已经尝试了readlock限制,这对这里没有影响。
@Override
public void configure() throws Exception {
if (validateConfiguration()) {
final String fromStr = String.format("%s://%s@%s:%s/%s?password=RAW(%s)&recursive=%s&stepwise=%s&useList=%s&passiveMode=%s&disconnect=%s"
+ "&move=.processed"
+ "&maxMessagesPerPoll=0"
+ "&eagerMaxMessagesPerPoll=false"
+ "&sortBy=file:modified"
+ "&sendEmptyMessageWhenIdle=false"
+ "&delay=60000"
+ "&initialDelay=60000"
+ "&connectTimeout=15000"
+ "&localWorkDirectory=/tmp"
+ "&readLockMinLength=0"
, transport, username, host, port, path, password, recursive, stepwise, useList, passiveMode, disconnect);
// Format the To Endpoint from Parameter(s).
final String toStr = String.format("%s", toEndpoint);
我将路线更改为如下所示,试图简化它。但它仍然无法正常工作,因为它可以接受所有文件,甚至是我不想处理的-0-零长度文件。 我确实相信这是选择的方式。当形成简单的陈述时,有些事情是不正确的。我已经尝试了许多组合都产生相同的结果。
from(fromStr)
.routeId("Zipped.Only")
.log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
.unmarshal(zipFile)
.split(body(Iterator.class))
.streaming()
.convertBodyTo(String.class)
.wireTap("file:" + fileArchive)
.choice()
.when(simple("${header.CamelFileLength} > 0" ))
.split(body().tokenize("\n"), new FleetAggregationStrategy()).streaming()
.process(new EndpointParametersProcessor(decoderName))
.end()
.to(toStr)
.endChoice()
.end();
屈服,我只想在文件包含数据或file.length!= 0时处理或移动到tobeprocessed文件夹。简单语句的使用方式有问题吗???我会继续尝试。
ge-digital/
├── [drwxr-xr-x 4.0K] core
│ ├── [drwxr-xr-x 4.0K] enriched
│ ├── [drwxr-xr-x 4.0K] mt1
│ │ └── [drwxr-xr-x 4.0K] processed
│ ├── [drwxr-xr-x 4.0K] mt2
│ │ └── [drwxr-xr-x 4.0K] processed
│ ├── [drwxr-xr-x 4.0K] mt3
│ │ └── [drwxr-xr-x 4.0K] processed
│ └── [drwxr-xr-x 4.0K] tobeprocessed
│ ├── [-rw-r--r-- 0] GCMS_20190420-0815.csv
│ ├── [-rw-r--r-- 0] GCMS_20190420-0816.csv
│ └── [-rw-r--r-- 0] GCMS_20190420-0817.csv
├── [drwxr-xr-x 4.0K] dbase
├── [drwxr-xr-x 4.0K] fleet
│ └── [drwxr-xr-x 4.0K] core
│ ├── [drwxr-xr-x 4.0K] archive
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0815.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0816.csv
│ │ └── [-rw-r--r-- 0] GCMS_20190420-0817.csv
│ └── [drwxr-xr-x 4.0K] error
└── [drwxr-xr-x 4.0K] upload
除了文件长度/大小错误之外,路由现在基本正常运行。它是原始文件的长度,而不是分割后的文件的长度。我该如何解决?
分割前-CamelFileLength:598和file.length:598
分割后-CamelFileLength:598和file.length:598
from(fromStr)
.routeId("Zipped.Only")
.log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
.unmarshal(zipFile)
.split(body(Iterator.class))
.streaming()
.convertBodyTo(String.class)
.wireTap("file:" + fileArchive)
.log(LoggingLevel.INFO, "before split - CamelFileLength: ${header.CamelFileLength} and file.length: ${file:length}")
.split(body().tokenize("\n"), new FleetAggregationStrategy()) //.streaming()
.process(new EndpointParametersProcessor(decoderName))
.end()
.choice()
//.when(simple("${file:length} > 0"))
.when(simple("${header.CamelFileLength} > '0'"))
.log(LoggingLevel.INFO, "after split - CamelFileLength: ${header.CamelFileLength} and file.length: ${file:length}")
.to(toStr)
.otherwise()
.log(LoggingLevel.INFO, "Message received ${file:name} is Empty or Null")
.to("file:" + errorArchive)
.end();
最终,好的,我们终于可以正常工作了。男人,像这样的小事情会让你有点退缩。对于那些有兴趣并可能帮助您的人。
我当时使用的是body.size,hmmm,没有给出身体的尺寸,然后我使用了body.length,这样就可以了。我无法使用许多不错的静态方法,我想我需要升级到新的骆驼版本。无论如何,问题在于诸如CamelFileLength之类的标头包含原始文件的长度/大小,而不是通过解压缩zipfile并拆分所有文件而拆分的标头。我一直在使用标头,直到意识到上面的内容,因此,我们将body()用作谓词,并且可以正常工作,并使用length
} else if (Boolean.parseBoolean(isCompressedOnly)) { //Only Zipped or Compressed
ZipFileDataFormat zipFile = new ZipFileDataFormat();
zipFile.setUsingIterator(true);
from(fromStr)
.routeId("Zipped.Only")
.log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
.unmarshal(zipFile)
.split(body(Iterator.class))
.streaming()
.convertBodyTo(String.class)
.wireTap("file:" + fileArchive)
.split(body().tokenize("\n"), new FleetAggregationStrategy()).streaming()
.process(new EndpointParametersProcessor(decoderName))
.end()
.choice()
.when(simple("${body.length} > '0'" ))
.to(toStr)
.end();
// .when(simple("${file:length} == 0"))
// .when(simple("${header.CamelFileLength} == 0" ))
// .when(header("CamelFileLength").isEqualTo(0))
// .when(body().isNull())
// .when(body().isNotNull())
// .when(header("CamelFileLength").isEqualTo(0))
// .when(simple("${header.CamelFileLength} < 10" ))
// .when(simple("${header.CamelFileLength} &eq; 0" ))
// .when(simple("${file:length} == null"))
} else {
收益:
ge-digital/
├── [drwxr-xr-x 4.0K] core
│ ├── [drwxr-xr-x 4.0K] enriched
│ ├── [drwxr-xr-x 4.0K] error
│ │ └── [-rw-r--r-- 47] GCMS_2019-04-23_05-27-18.666.csv
│ ├── [drwxr-xr-x 4.0K] mt1
│ │ └── [drwxr-xr-x 4.0K] processed
│ ├── [drwxr-xr-x 4.0K] mt2
│ │ └── [drwxr-xr-x 4.0K] processed
│ ├── [drwxr-xr-x 4.0K] mt3
│ │ └── [drwxr-xr-x 4.0K] processed
│ │ ├── [-rw-r--r-- 2.9K] GCMS_112-A-001_Gas_Turbine_2019-04-23_05-29-18.csv
│ │ ├── [-rw-r--r-- 2.1K] GCMS_112-A-001_Gas_Turbine_cw_2019-04-23_05-29-18.csv
│ │ ├── [-rw-r--r-- 911] GCMS_112-A-001_Generator_2019-04-23_05-29-18.csv
│ │ ├── [-rw-r--r-- 2.8K] GCMS_112-A-002_Gas_Turbine_2019-04-23_05-29-18.csv
│ │ ├── [-rw-r--r-- 2.1K] GCMS_112-A-002_Gas_Turbine_cw_2019-04-23_05-29-18.csv
│ │ └── [-rw-r--r-- 888] GCMS_112-A-002_Generator_2019-04-23_05-29-18.csv
│ └── [drwxr-xr-x 4.0K] tobeprocessed
│ ├── [-rw-r--r-- 935K] GCMS_2019-04-23_05-27-44.673.csv
│ ├── [-rw-r--r-- 0] GCMS_2019-04-23_05-27-44.673.csv.camelLock
│ ├── [-rw-r--r-- 941K] GCMS_2019-04-23_05-28-07.013.csv
│ ├── [-rw-r--r-- 936K] GCMS_2019-04-23_05-28-33.694.csv
│ ├── [-rw-r--r-- 939K] GCMS_2019-04-23_05-29-02.300.csv
│ └── [-rw-r--r-- 946K] GCMS_2019-04-23_05-29-28.928.csv
├── [drwxr-xr-x 4.0K] dbase
├── [drwxr-xr-x 4.0K] fleet
│ └── [drwxr-xr-x 4.0K] core
│ ├── [drwxr-xr-x 4.0K] archive
│ │ ├── [-rw-r--r-- 981K] GCMS_20190319-0429.csv
│ │ ├── [-rw-r--r-- 977K] GCMS_20190319-0437.csv
│ │ ├── [-rw-r--r-- 982K] GCMS_20190319-0446.csv
│ │ ├── [-rw-r--r-- 977K] GCMS_20190319-0454.csv
│ │ ├── [-rw-r--r-- 980K] GCMS_20190319-0502.csv
│ │ ├── [-rw-r--r-- 988K] GCMS_20190319-0511.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0815.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0816.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0817.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0818.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0819.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0820.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0821.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0822.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0823.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0824.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0825.csv
│ │ ├── [-rw-r--r-- 15K] GCMS_20190420-0826.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0827.csv
│ │ ├── [-rw-r--r-- 0] GCMS_20190420-0828.csv
│ │ └── [-rw-r--r-- 0] GCMS_20190420-0829.csv
│ └── [drwxr-xr-x 4.0K] error
└── [drwxr-xr-x 4.0K] upload