亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從處理器內部設置 Camel 交換屬性

從處理器內部設置 Camel 交換屬性

尚方寶劍之說 2022-07-20 10:59:19
Java 8 和 Camel 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,并將該屬性的初始值設置為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 = ...似乎并沒有被日志輸出讀?。篈bout to update fizzId...fizzId = null所以我認為我的處理器正在接收交換屬性的副本,fizzId但是重新分配它的值內聯實際上并沒有修改路由其余部分的實際值。關于如何做到這一點的任何想法?
查看完整描述

2 回答

?
青春有我

TA貢獻1784條經驗 獲得超8個贊

不要將屬性傳遞給處理器,而是接受交換 - 然后您可以在交換上設置屬性。



查看完整回答
反對 回復 2022-07-20
?
森林海

TA貢獻2011條經驗 獲得超2個贊

您可能需要參考更高的東西來設置值。嘗試對完整的屬性映射 @Properties 使用注釋,或者讓您的 WidgetFetcher 實現處理器以獲取對完整交換的引用。



查看完整回答
反對 回復 2022-07-20
  • 2 回答
  • 0 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號