Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Apache Camel - Connection Beans Without Spring

DZone's Guide to

Apache Camel - Connection Beans Without Spring

· Integration Zone
Free Resource

Discover how developers can easily discover existing APIs and back-end data sources and create new APIs and microservices based on the popular open-source Node.js Express and LoopBack® frameworks.  Brought to you in partnership with IBM.

While writing some tests for an Apache Camel project, I just spent rather longer than I'd have liked trying to work out how to configure a connection bean for Mongo without using Spring.

Since I hide my embarrassments in public I thought I'd best share with anyone else with brain freeze.
public class SomeTest extends CamelTestSupport {

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("direct:findAll")
                    .to("mongodb:myConnectionBean?database=flights&collection=tickets&operation=findAll")
                    .to("mock:resultFindAll");

            }
        };
    }

    @Override
    protected JndiRegistry createRegistry() throws Exception {
        JndiRegistry reg = new JndiRegistry(createJndiContext());
        Mongo connectionBean = new Mongo("localhost", 27017);
        reg.bind("myConnectionBean", connectionBean);
        return reg;
    }

    @Test
    public void testSomething() throws InterruptedException {
        // test something here
    }

}
Don't forget you need the camel-mongodb artifact in your pom.xml file. Good luck fellow travellers.

Learn about the comprehensive capabilities to create, run, manage, secure and monetize APIs and microservices with API Connect.  Brought to you in partnership with IBM.

Topics:

Published at DZone with permission of Col Wilson, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}