我有下面的代码。fireTime header 在 split 之前可用,我想在 split 调用之后使用它,但根据日志不可用。 pom中的Camel版本是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
最佳答案
您可以将变量存储在属性中并稍后在链中使用它们,请参阅下面的 .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 ");
}
关于java - 调用 split 后如何将 header 从父交换复制到子交换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56438591/