骆驼如何在注册表中添加一些内容-通常使用Java [英] Camel how to add something to registry - with java, in general
问题描述
有时我必须将一个对象添加到骆驼注册表中(当然使用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
,我确信会有代码添加我的bean,但是;
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屋!