我有一条路由到2个地方的路由。如果在调用该位置的1时发生异常,则无法保留聚合结果。在onException的处理器内部,不存在我在聚合过程中创建的Map。我正在使用骆驼2.25。
onException(RuntimeException.class)
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Map<String, String> results = exchange.getProperty(SimpleAggregationStrategy.RESULTS, Map.class);
System.out.println(results);
}
});
from(DIRECT_FIRST)
.log("First route")
.setBody(constant("FIRST TEXT"));
from(DIRECT_SECOND)
.log("Second route")
.setBody(constant("SECOND TEXT"))
.throwException(new RuntimeException("Dummy Exception"));
from(DIRECT_ENTRY)
.multicast().stopOnException().aggregationStrategy(new AggregationStrategy() {
public static final String RESULTS = "RESULTS";
@Override
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
System.out.println("INSIDE SimpleAggregationStrategy !!!!!!!!!!!!!!!!");
Map<String, String> results;
if (oldExchange != null) {
results = oldExchange.getProperty(RESULTS, Map.class);
} else {
results = new HashMap<>();
}
results.put(newExchange.getIn().getBody(String.class), newExchange.getIn().getBody(String.class));
return newExchange;
}
})
.to(DIRECT_FIRST, DIRECT_SECOND);
stopOnException()
而中止了处理,因此> 不返回(不完整的)结果] >>。 您可以尝试将聚合策略放入上下文托管的Bean中,并使Map成为可通过getter方法访问的实例变量。 如果发生异常,您可以尝试从Bean获取不完整的Map。但是我不知道它是否仍然保留数据,或者在处理中止时是否将其清空。