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

标签 apache-camel

有时我必须向 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/

相关文章:

java - 无效查询 : URI parse exception in Apache HTTP Client used in Camel

java - CAMEL JMS 崩溃并停止生成消息

java - 在 pollEnrich 结束策略之前删除文件

apache-camel - Apache Camel 拆分大文件

java - 到达 Controller 时子类型数据丢失

java - 在spring xml中定义Camel路由有什么优缺点?

tomcat - 使用 KeepAlive 优化 Camel HTTP4

java - 从 service-mix 文件轮询器迁移到 apache Camel 文件轮询器

java - 如何在 Camel 处理器中调用unmarshal()?

java - 使用 Mockito Mock 对 Apache Camel Route 进行 JUnit 测试不会失败