gpt4 book ai didi

apache-camel - Camel 如何向注册表添加一些东西 - 通常使用 java

转载 作者:行者123 更新时间:2023-12-03 16:13:59 25 4
gpt4 key购买 nike

有时我必须向 Camel 注册表添加一个对象(当然是用java)。在大多数情况下,它是一个 dataSource 。

我的问题是我无法弄清楚一般的工作方式。

我总是开始获取注册表:

getContext().getRegistry();

但是“注册表”没有任何添加对象的方法。所以我必须尝试(使用调试器)正在使用什么样的注册表
getContext().getRegistry(some.class)<some method to add something>;

例如在一个项目( Camel 蓝图)中,我必须调用
SimpleRegistry registry = new SimpleRegistry();
registry.put("some", bean);
getContext().getRegistry(CompositeRegistry.class).addRegistry(registry);

现在我创建了一个具有相同结构的项目(也是相同的 maven 父级),但现在上面的代码停止工作,因为出于某种原因,现在 Camel 使用 PropertyPlaceholderDelegateRegistry我确信会有代码添加我的 bean,但是;

是否有适用于每个设置的代码以向 Camel 注册表添加内容?

最佳答案

这是在 RouteBuilder 类中向注册表添加内容的一种方法。下面我添加了一个 TCPServerInitializerFactory,稍后将使用它。我总是使用 Camel 蓝图原型(prototype),但使用 java dsl 创建路由。这对我来说很好。

TCPServerInitializerFactory serverFactory = new TCPServerInitializerFactory(null);
final CamelContext camelContext = getContext();
final org.apache.camel.impl.SimpleRegistry registry = new org.apache.camel.impl.SimpleRegistry();
final org.apache.camel.impl.CompositeRegistry compositeRegistry = new org.apache.camel.impl.CompositeRegistry();
compositeRegistry.addRegistry(camelContext.getRegistry());
compositeRegistry.addRegistry(registry);
((org.apache.camel.impl.DefaultCamelContext) camelContext).setRegistry(compositeRegistry);
registry.put("spf", serverFactory);

关于apache-camel - Camel 如何向注册表添加一些东西 - 通常使用 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40503184/

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