Apache Camel adapt()方法在版本4中删除

7kjnsjlb  于 8个月前  发布在  Apache
关注(0)|答案(1)|浏览(84)

在从ApacheCamel3迁移到版本4的过程中,我遇到了这样一个事实,即adapt()方法已从camel上下文中删除,并且不再可能适应ModelCamelContext

ModelCamelContext modelContext = context.adapt(ModelCamelContext.class);        
RouteDefinition route = modelContext.getRouteDefinition(routeId);

字符串
official migration guide只提到,
将org.apache.camel.CamelContext中的adapt()替换为getCamelContextExtension
但遗憾的是,它没有详细说明API是如何兼容的。我正在努力解决一个用例,我需要动态操作路由定义,这在旧的ModelCamelContext方法中相当简单。我需要获取路由定义,将其从上下文中删除,再次添加不同的路由定义并操作其输出(getOutputs方法)。
有什么想法可以在Apache Camel版本4中实现吗?

thigvfpy

thigvfpy1#

Camel迁移指南https://camel.apache.org/manual/camel-4-migration-guide.html提到了以下迁移代码:

Removed getExtension from the interface CamelContext

Use getCamelContextExtension instead. For example ManagedCamelContext managed = context.getCamelContextExtension().getContextPlugin(ManagedCamelContext.class);

字符串
基于此,我们能够通过以下方式获得模型扩展:

var model = context.getCamelContextExtension().getContextPlugin(Model.class);

相关问题