java - 在路由骆驼apache之间传递参数
问题描述
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 转到每日文件夹。还有其他路线,例如每月,每周。因此,他们将有不同的路线和不同的 crons,就像第一个一样。但他们会用准备好的 cron 表达式调用第二个。
每个文件夹都不一样。
这是全球性的:
private String camelCronExpression;
我还尝试将那条路线放在第一个交换位置。我还输入了开始代码。
exchange.setProperty("xxx", camelCronExpression);
我试图这样得到它:因为设置为类的全局变量可能不好并给出错误:
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)
解决方案
您可以使用以下语法之一通过简单的语言取回您的交换属性。
- 交换属性.foo
- 交换属性[foo]
- 交换属性.foo.OGNL
在 Java DSL 中,
from("direct:ReconciliationBatchRoute.getFileFromSFTP")
.pollEnrich()
.simple("${exchangeProperty.xxx}")
从exchangeProperty 语言,它也可以通过
from("direct:ReconciliationBatchRoute.getFileFromSFTP")
.pollEnrich()
.exchangeProperty("xxx")
推荐阅读
- node.js - 我正在尝试对猫鼬数据库中的数据进行排序,并使用 find() 函数获取输出,但我想使用 paginate() 函数对数据进行排序
- react-native - 在 react-native 上将 base64 转换为 blob 时获取错误
- python - Self Attention 不如 RNN 好?
- volttron - 在 Volttron 平台中导入 Pandas 时出错
- xml - 如何使用 XML::Simple 根据 Perl 中的 XML 属性内容修改 XML 元素?
- visual-studio-code - 自动格式化,使用 Visual Studio Code 自动换行(在 Mac 上)
- outlook - UiPath StudioX - Outlook 桌面应用程序 COM 加载项错误
- python - tkinter 无法识别图像数据
- android - 如何更改缺少中间名的android包名称?
- php - 如何将加载的自定义计费字段保存到 woocommerce 订单元(管理员订单)?