这是Apache Camel路线:
ZooKeeperRoutePolicy routePolicy = new ZooKeeperRoutePolicy("zookeeper:localhost:2181/fuse-example/routePolicy", 1);
from("file:camelInpit").routeId("systemARoute")
.routePolicy(routePolicy)
.log(LoggingLevel.ERROR, "Starting route")
[...]
我想在测试中删除routePolicy,因为测试环境中没有ZooKeeper,但这并不像看起来那样容易
context.getRouteDefinition("systemARoute").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("direct:aaa");
weaveByType(RouteDefinition.class).selectIndex(1).remove();
}
});
weaveById("policy")
和设置ID routePolicy(...).id("policy")
并没有帮助。测试时如何动态删除
RoutePolicies
? 最佳答案
您可以访问原始路由并将其路由策略设置为null
context.getRouteDefinition("systemARoute").adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
getOriginalRoute().setRoutePolicies(null);
}
});
但是我们也许应该为此添加流利的DSL构建器以使其脱颖而出?