骆驼如何向注册表添加一些东西 - 通常使用 java [英] Camel how to add something to registry - with java, in general

查看:9
本文介绍了骆驼如何向注册表添加一些东西 - 通常使用 java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我必须向骆驼注册表添加一个对象(当然是使用 java).在大多数情况下,它是一个数据源.

sometimes I have to add an object to camel registry (of course with java). In most cases it is a dataSource .

我的问题是我想不出一个通用的工作方式.

My problem is I can't figure out a general working way.

我总是开始获取注册表:

I always begin to acquire the registry:

getContext().getRegistry();

但是注册表"没有任何添加对象的方法.所以我必须尝试(使用调试器)正在使用什么样的注册表

But "Registry" does not have any method to add an object. So I have to try (with debugger) what kind of registry is in use

getContext().getRegistry(some.class)<some method to add something>;

例如在一个项目中(骆驼蓝图)我必须调用

For example in one project (camel blueprint) I have to call

SimpleRegistry registry = new SimpleRegistry();
registry.put("some", bean);
getContext().getRegistry(CompositeRegistry.class).addRegistry(registry);

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

Now I created a project with same structure (also same maven parent) but now the code from above stops working because for some reason now camel uses a PropertyPlaceholderDelegateRegistry I am sure there will be code to add my bean but;

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

Is there code that works with every setup to add something to camels registry?

推荐答案

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

Here is one way of adding stuff to the registry in a RouteBuilder class. Below I am adding a TCPServerInitializerFactory which will be used later on. I always use the camel-blueprint archetype but create routes using java dsl. This works fine for me.

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);

这篇关于骆驼如何向注册表添加一些东西 - 通常使用 java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆