我有这些依赖关系:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<exclusions>
<exclusion>
<artifactId>jaxp-ri</artifactId>
<groupId>com.sun.xml.parsers</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<exclusions>
<exclusion>
<artifactId>jaxp-ri</artifactId>
<groupId>com.sun.xml.parsers</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<exclusions>
<exclusion>
<artifactId>jaxp-ri</artifactId>
<groupId>com.sun.xml.parsers</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
我还添加了这个:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz2</artifactId>
</dependency>
我有一个简单的路线:
from("file:C:\dev\Repository\ware3\ff.txt?scheduler=quartz2&scheduler.cron=0/3 0/1 * 1/1 * ? *")
.routeId("testRoute")
.log(LoggingLevel.INFO, "******n*******n******File asdsaw name : fsa");
它应该每 3 秒调用一次此方法,但我看不到任何带有 **** 或"testroute"的日志。
我想做的是根据石英检查本地文件夹。如果我能成功,我会尝试FTP,但现在即使它也不能用于本地文件夹。
路径是正确的,因为我可以获取文件
File initialFile = new File("C:\dev\Repository\ware3\ff.txt");
InputStream targetStream = null;
List<String> fileAsLines = null;
targetStream = new FileInputStream(initialFile);
文件端点语法为:
file:directoryName[?options]
请参阅文件组件文档:
仅目录
Camel仅支持配置了起始目录的端点。因此,目录名称必须是目录。如果您只想使用单个文件,则可以使用文件名选项,例如通过设置
fileName=thefilename
因此,请将file:C:\dev\Repository\ware3\ff.txt?scheduler=...
替换为file:C:\dev\Repository\ware3?fileName=ff.txt&scheduler=...
此外,根据您的 Camel 版本,您可能需要将 cron 表达式中的空格替换为+
,例如scheduler.cron=0/3+0/1+*+1/1+*+?+*
。如果您希望文件每 3 秒轮询一次,那么表达式可以简化为0/3+*+*+*+*+?