我有下面的代码。fireTime标头在split之前可用,我也想在split调用之后使用它,这在每个日志中都不可用。 pom中的骆驼版本为2.17.3。 代码和日志均如下所示。
@Override
public void configure() throws Exception
{
LOGGER.debug("Configuring client for UnicomOrderReader::synchInventoryAndOrders");
from("quartz2://timer1?cron=0 0 * ? * * *")
.log(" Unicom Job fired at ${header.fireTime}")
.process(activeInitializedClientTaskProcessor)
.split(simple("${body}"))
.log("After Split Unicom Job fired at ${header.fireTime}")
.to("activemq:queue:" + ActiveMQNames.UNICOM_INVENTORY_ORDER_READER_QUEUE)
.log("Executed route to sync inventory and orders from Unicom ");
}
记录如下输出:-
oms-04 Jun 2019 12:00:00,048 INFO DefaultQuartzScheduler-camel-1_Worker-1 [route42] - Unicom Job fired at Tue Jun 04 12:00:00 IST 2019
oms-04 Jun 2019 12:00:00,280 INFO DefaultQuartzScheduler-camel-1_Worker-1 [route42] - After Split Unicom Job fired at
oms-04 Jun 2019 12:00:00,298 INFO DefaultQuartzScheduler-camel-1_Worker-1 [route42] - After Split Unicom Job fired at
oms-04 Jun 2019 12:00:00,312 INFO DefaultQuartzScheduler-camel-1_Worker-1 [route42] - After Split Unicom Job fired at
oms-04 Jun 2019 12:00:00,317 INFO DefaultQuartzScheduler-camel-1_Worker-1 [route42] - After Split Unicom Job fired at
oms-04 Jun 2019 12:00:00,322 INFO DefaultQuartzScheduler-camel-1_Worker-1 [route42] - After Split Unicom Job fired at
oms-04 Jun 2019 12:00:00,327 INFO DefaultQuartzScheduler-camel-1_Worker-1 [route42] - After Split Unicom Job fired at
oms-04 Jun 2019 12:00:00,332 INFO DefaultQuartzScheduler-camel-1_Worker-1 [route42] - After Split Unicom Job fired at
答案 0 :(得分:0)
您可以将变量存储在属性中,并在链的后面使用它们,请参见下面的.setProperty("myHeader", header("theheadername"))
:
@Override
public void configure() throws Exception
{
LOGGER.debug("Configuring client for UnicomOrderReader::synchInventoryAndOrders");
from("quartz2://timer1?cron=0 0 * ? * * *")
.log(" Unicom Job fired at ${header.fireTime}")
.process(activeInitializedClientTaskProcessor)
.setProperty("myHeader", header("theheadername"))
.split(simple("${body}"))
//here you can access ${property.myHeader} for example by passing it as an argument to a bean method
.bean(myBean, "myMethod(${property.myHeader}, ${Body})")
.log("After Split Unicom Job fired at ${header.fireTime}")
.to("activemq:queue:" + ActiveMQNames.UNICOM_INVENTORY_ORDER_READER_QUEUE)
.log("Executed route to sync inventory and orders from Unicom ");
}