java 8和骆驼2.19.x此处。我有以下骆驼路线:
<route id="widgetProcessing">
<from uri="activemq:inputQueue"/>
<to uri="{{widgetFetcher}}"/>
</route>
和widgetFetcher
处理器:
@Component("widgetFetcher")
public class WidgetFetcher {
private WidgetDao widgetDao;
public WidgetFetcher(WidgetDao widgetDao) {
this.widgetDao = widgetDao;
}
public Widget getWidgetToProcess() {
// get the next widget id from the database
final Integer firstWidgetId = widgetDao.getFirstSubmittedWidgetId();
// Do lots of stuff with 'firstWidgetId' down here...
}
}
我想在<from>
之后和WidgetFetcher
之前创建一个Exchange属性,并将此属性的初始值设置为null
;然后有条件地将其值设置为WidgetFetcher
内部的其他东西。此外,我希望将其重新分配的价值在其余的路线/处理过程中"粘贴"。所以类似:
<route id="widgetProcessing">
<from uri="activemq:inputQueue"/>
<setProperty propertyName="fizzId">
<constant>null</constant>
</setProperty>
<to uri="{{widgetFetcher}}"/>
<log message="fizzId = ${property[fizzId]}" loggingLevel="ERROR"/>
</route>
,然后:
public Widget getWidgetToProcess(@ExchangeProperty("fizzId") final String fizzId) {
// get the next widget id from the database
final Integer firstWidgetId = widgetDao.getFirstSubmittedWidgetId();
if (someMethodReturnsTrue()) {
// Does this actually get saved outside the
log.info("About to update fizzId...")
fizzId = UUID.randomUUID().toString();
}
// Do lots of stuff with 'firstWidgetId' down here...
}
但是,在运行时,本地分配fizzId = ...
似乎并不如日志输出所读:
About to update fizzId...
fizzId = null
因此,我认为我的处理器正在接收fizzId
Exchange属性的复制,但是重新测试其值内联的值实际上并未修改该路由的其余部分的实际值。关于如何执行此操作的任何想法?
,而不是将属性传递给处理器,接受交易所 - 然后您可以在Exchange上设置属性。
您可能需要提及更高的东西来设置该值。尝试将注释用于完整的属性映射@properties,或者让您的WidgetFetcher实施处理器获取对完整交换的参考。
参考:骆驼注释