from("quartz2://dailyCamelScheduler?cron=" +
"0+0/1+*+*+*+?+*" )
.log(LoggingLevel.INFO, "ReconciliationBatchRoute", "Daily camel route called")
.routeId("dailyCamelRoute")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
camelCronExpression = "sftp://"
// + username + "@"
+ hostAddress
+ ":22"
+ "/POLICE_BELGE_MUTABAKAT_"
+ "DAILY"
// + "&" +
+"?username=" + username
+ "&password=" + password
+ "&fileName=" + fileName
+ "&autoCreate=false"
+ "&strictHostKeyChecking=no"
+ "&preferredAuthentications=publickey,password";
exchange.setProperty("xxx", camelCronExpression);
}
})
.setProperty("typeOfRoute").constant(DocumentPolicyJobTypeEnum.DAILY)
.to("direct:ReconciliationBatchRoute.getFileFromSFTP");
from("direct:ReconciliationBatchRoute.getFileFromSFTP")
.pollEnrich()
.simple(camelCronExpression)
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
logger.info("MutabakatLog Strat Mutabakat");
List<String> strings = IOUtils.readLines(exchange.getIn().getBody(InputStream.class));
logger.info("qqsize: {}", strings.size());
}
})
.stop();
第一条路线是每天安排的每日路线。调用时,它将调用第二条路径以从SFTP转到每日文件夹。还有其他路线,例如每月,每周。因此,他们将拥有与第一个路线不同的路线和不同的路段。但是他们会调用带有准备好的cron表达式的第二个。
每个文件夹都不同。
这是全局的:
private String camelCronExpression;
我还试图将这条路线放在第一条路线上。我还输入了开始代码。
exchange.setProperty("xxx", camelCronExpression);
我试图这样得到它:因为设置为class的全局变量可能不好,并给出了错误:
private String expression;
from("direct:ReconciliationBatchRoute.getFileFromSFTP")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
expression = exchange.getProperty("xxx")
}
})
.pollEnrich()
.simple(expression) //here expression seems null
但是我无法在.simple()中获得表达式
您认为这些方式很好吗?以及如何使它不为空?
我无法同时进行投票:
from("direct:ReconciliationBatchRoute.getFileFromSFTP")
.pollEnrich()
.simple(camelCronExpression)
答案 0 :(得分:1)
您可以使用以下一种语法,通过simple language来找回交换属性。
在Java DSL中,
from("direct:ReconciliationBatchRoute.getFileFromSFTP")
.pollEnrich()
.simple("${exchangeProperty.xxx}")
在exchangeProperty language中,它可能也可以使用
from("direct:ReconciliationBatchRoute.getFileFromSFTP")
.pollEnrich()
.exchangeProperty("xxx")