如何在 Java 中设置骆驼上下文和注册表 [英] How to setup camel context and registry within java

查看:28
本文介绍了如何在 Java 中设置骆驼上下文和注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个独立的骆驼应用程序.我只想使用 java (因为编译器会告诉你什么是错的).为了使我的代码通过测试减少耦合和重用,我想将上下文和注册表的创建解耦到单独的类.我刚开始扩展 DefaultCamelContext - 这是一个好主意还是我应该扩展/实现一些其他类?在这个类中,我想使用我自己的注册表(它绑定了一些 bean 实例)类.我找到了 setRegistry(org.apache.camel.spi.Registry) 方法.

I am creating a stand alone camel application. I want to use only java (because the compiler tells whats wrong). To make my code less coupled and reusable by tests i want to decouple the creation of context and registry to separate classes. I just started to extend DefaultCamelContext - is this a good idea or should i extend/implement some other class? Within this class i want to use my own registry (it binds some bean instances) class. I found method setRegistry(org.apache.camel.spi.Registry).

但是如何实现这样的注册表?是否还有defaultRegistry"?(对于测试,有一个 createRegistry(),是否有测试之外的东西?)

But how to implement such an registry? Is there also a "defaultRegistry"? (for tests there is an createRegistry(), is there something for outside the tests?)

最后,我想使用依赖注入 (guice) 将所有内容粘合在一起:注册表将注入 bean 实例,然后将注册表注入上下文中,然后将上下文注入到我的主类中,而不是创建主", 设置上下文并run()"它.

At the end i want to use dependency injection (guice) to glue all stuff together: the registry will inject bean-instances, the registry is then injected in context and context is injected in my main-class than creates "main", sets context and "run()"s it.

推荐答案

Camel 支持 可插拔注册表策略...所以你应该能够实现 org.apache.camel.spi.Registry 接口并调用 setRegistry(myImpl)...

Camel supports a pluggable registry strategy...so you should be able to implement the org.apache.camel.spi.Registry interface and call setRegistry(myImpl)...

支持多个(Simple、Jndi 等)注册中心,它们可能满足您的需求或作为示例...

there are several (Simple, Jndi, etc) registries that are supported that might meet your needs or serve as an example...

例如,这里是 SimpleRegistry 实现类...

for example, here is the SimpleRegistry implementation class...

https://git-wip-us.apache.org/repos/asf?a=camel.git;blob_plain;f=camel-core/src/main/java/org/apache/camel/impl/SimpleRegistry.java;h=d2a4a21c9f9fbc70f45fd485d1c46c8a20b9afea;hb=HEAD

这篇关于如何在 Java 中设置骆驼上下文和注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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