How to setup camel context and registry within java

半世苍凉 提交于 2019-12-12 04:18:11

问题


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

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

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.


回答1:


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

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

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

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



来源:https://stackoverflow.com/questions/23224395/how-to-setup-camel-context-and-registry-within-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!