- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果我在路由处理交换之前删除文件,我会得到异常:GenericFileOperationFailedException:无法重命名文件。 PollEnrich 的策略尝试将文件从 someFolder 移动到 someFolder/.camel。
from("wmq:queue:someQueue")//Here we get the message with information about the file
...//some logic
.pollEnrich("file:someFolder?fileName=someFile")
...//some logic
.choice()
.when(...)//Here we compare checksum from message with checksum of the file
.process(new SomeClassProcess)//And if they are different file will be deleted from someFolder
.otherwise()
.to(someAnotherFolder)
.end();
我正在尝试使用 .rollback("errorMessage")
onException(RollbackExchangeException.class)
.log(LoggingLevel.WARN, "SomeExcptn");
from("wmq:queue:someQueue")
...//some logic
.pollEnrich("file:someFolder?fileName=someFile")
...//some logic
.choice()
.when(...)
.process(new SomeClassProcess)//it will delete someFile from someFolder
.rollback()
.otherwise()
.to(someAnotherFolder)
.end();
但是现在我在应用程序日志中发现了垃圾 - CamelExecutionException。它可以工作,但是你能用另一种方式帮助解决它吗?
附注我不知道在向 pollEnrich 提供 URI 之前是否需要删除文件,这就是我不使用 noop=true 的原因。在 .otherwise() 中,我需要将文件移动到 .camel。
感谢您的建议!
最佳答案
我认为您不需要使用任何处理器来删除文件。你可以这样做:
@Produce(uri = "direct:start")
ProducerTemplate producerTemplate;
@Autowired
CamelContext camelContext;
@Before
public void before() {
File outputDir = new File("transfer/outbox");
File tmpDir = new File("transfer/tmp");
for (File file : outputDir.listFiles())
file.delete();
for (File file : tmpDir.listFiles())
file.delete();
}
@Override
public RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("file:transfer/inbox?noop=true")
.to("file:transfer/tmp")
.pollEnrich("file:transfer/tmp")
.choice()
.when(header(Exchange.FILE_NAME).isEqualTo("Message1.txt"))
.log(LoggingLevel.ERROR, "${header[CamelFileName]} This file is discarded")
.otherwise()
.to("file:transfer/outbox")
.end();
}
};
}
@Test
public void smokeTest() throws Exception {
NotifyBuilder notifyBuilder = new NotifyBuilder(context)
.wereSentTo("file:transfer/outbox").whenDone(1)//Just to make the test enough time to complete
.create();
notifyBuilder.matches(5, TimeUnit.SECONDS);
File inputDur = new File("transfer/inbox/");
assertEquals(inputDur.listFiles().length, 2); // Message1.txt, Message2.txt (no .camel because ?noop=true)
File outputDir = new File("transfer/outbox/");
assertEquals(outputDir.listFiles().length, 1); // Message2.txt
File tmpDir = new File("transfer/tmp/");
assertEquals(tmpDir.listFiles().length, 1); // .camel
}
或者如果您不关心自己记录它,更合适的方法是使用消息过滤器而不是基于内容的路由器:
from("file:/path/to/your/file")
.filter(somePredicate)
.to("file:/where/you/want/it/to/move")
在camel在飞行中的交换中使用文件时删除文件不是什么事情,camel确实用另一个后缀为.camelLock的文件锁定该文件,以防止其他路线消耗他,但用处理器修改这个文件根本不安全。
此外,我在您的示例中没有看到任何 ?noop=true 。如果您想删除或移动文件,则使用 ?noop 不相关。
关于java - 在 pollEnrich 结束策略之前删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36068307/
我正在读取和处理来自 2 个不同文件位置的 2 个文件并比较内容。如果第二个文件不可用,则其余过程将使用第一个文件执行。如果第二个文件可用,比较过程应该发生。为此,我正在使用 camel pollEn
我有一条由restful触发的直接Camel路线。 Restful 传递 Exchange 主体内的文件名(需要处理)。路线很简单: from("direct:myRoute") .log("R
如果我在路由处理交换之前删除文件,我会得到异常:GenericFileOperationFailedException:无法重命名文件。 PollEnrich 的策略尝试将文件从 someFolder
我有这条路线 from(URI_WEBSERVICE) .convertBodyTo(Entrada.class) .process(new ProcessorTratarWS()) .pollEnr
使用 JPA Consumer、transform 和其他中间路线操作构建 Camel ETL 路线示例。这包括针对另一个 JPA 实体的额外 pollEnrich 步骤。 pollEnrich 步骤
第一个问题: 我无法真正理解enrich()和pollEnrich()之间的区别。也许 Camel 使用的术语不是很好。 我在这里阅读:http://camel.apache.org/content-
我有这条 Camel 路线 from("file:{{PATH_INPUT}}?charset=iso-8859-1&delete=true") .process(new Proces
Apache Camel 2.12.1 是否可以将 Camel CSV 组件与 pollEnrich 一起使用?我看到的每个例子都是这样的: from("file:somefile.csv").mar
在我的 Camel route ,我使用队列中的消息;每条消息都包含标题“pad”(路径)和文件前缀。例如: message1: pad="/some/dir", file="AAA"message2
我是一名优秀的程序员,十分优秀!