gpt4 book ai didi

java - 从处理器内部设置 Camel 交换属性

转载 作者:行者123 更新时间:2023-12-01 19:42:11 25 4
gpt4 key购买 nike

这里是 Java 8 和 Camel 2.19.x。我有以下 Camel 路线:

<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 内部的其他值。此外,我希望将这个重新分配的值保留为“stick”以用于剩余的路由/处理。所以类似:

<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副本交换属性,但重新分配其内联值实际上并不会修改路由其余部分的实际值。 知道如何做到这一点吗?

最佳答案

不要将属性传递给处理器,而是接受交换 - 然后您可以在交换上设置属性。

关于java - 从处理器内部设置 Camel 交换属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54990925/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com