BT

New Early adopter or innovator? InfoQ has been working on some new features for you. Learn more

Apache Camel 2.14: Java 8, Spring 4, REST DSL and Metrics

| by Matt Raible on Oct 21, 2014. Estimated reading time: 2 minutes |

The Apache Camel team recently released version 2.14, their 66th release. Camel is an open-source integration framework that provides components based on the popular enterprise integration patterns. It allows an application to define route and mediation rules in many domain-specific languages (DSLs), for example with Java, XML, Groovy and Scala.

New features include a REST DSL and Swagger integration for easily documenting an API, as well as new support for Java 8 (Java 6 is no longer supported) and Spring 4 (users of Spring 3.x or earlier will need to use camel-test-spring3 for testing). A Java 8 specific DSL that allows for lambda expressions was deferred until the next release.

In a blog post entitled Easy REST endpoints with Apache Camel 2.14, Christian Posta, Principal Middleware Specialist/Architect at Red Hat wrote:

With the 2.14, the DSL has been extended to make it easier to create REST endpoints. For example:

rest("/user").description("User rest service")
    .consumes("application/json").produces("application/json")

    .get("/{id}").description("Find user by id").outType(User.class)
        .to("bean:userService?method=getUser(${header.id})")

    .put().description("Updates or create a user").type(User.class)
        .to("bean:userService?method=updateUser")

    .get("/findAll").description("Find all users").outTypeList(User.class)
        .to("bean:userService?method=listUsers");

In this example, we can see we use the DSL to define REST endpoints, and it’s clear, intuitive and straightforward.

Other notable features introduced in this release include Netty 4.x support, an API component (that allows easier authoring of Camel components), more JMX beans, and Metrics integration for gathering various metrics directly from Camel routes. Supported metric types are counter, meter, histogram and timer. These statistics provide a way to measure and monitor the behaviour of your routes.

I recently integrated Metrics into an Apache Camel / CXF / Spring Boot application and found it took just one line in my CamelConfig.java class.

@Configuration
@ImportResource("classpath:META-INF/cxf/cxf.xml")
@ComponentScan("com.company.app")
public class CamelConfig extends CamelConfiguration {

    @Override
    protected void setupCamelContext(CamelContext camelContext) throws Exception {
        // make Camel aware of Spring Boot’s application.properties
        PropertiesComponent pc = new PropertiesComponent();
        pc.setLocation("classpath:application.properties");
        camelContext.addComponent("properties", pc);

        // enable performance metrics
        camelContext.addRoutePolicyFactory(new MetricsRoutePolicyFactory());
        super.setupCamelContext(camelContext);
    }
}

After enabling metrics, you can use the hawtio console to see performance statistics of your routes. It also allows you to view, edit, trace and debug Camel routes in your browser with an HTML5 / AngularJS application. Claus Ibsen, Principal Software Engineer at Red Hat, wrote a blog post called More metrics in Apache Camel 2.14 and included the following screenshot of hawtio displaying Camel route metrics.

Camel Route Metrics

Apache Camel 2.14 contains several new features and support for modern platforms. Its Java and Scala DSLs allow users to move away from XML and concentrate on core business logic. Its REST DSL provides a concise way to create REST endpoints that can be auto-documented with Swagger.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Java 8 support by Luke Dywicki

Support for Java 8 does not include lambda expressions. I guess it is limited only to runtime, but core is still not Java 8 compatible in terms of new features.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Login to InfoQ to interact with what matters most to you.


Recover your password...

Follow

Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.

Like

More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.

Notifications

Stay up-to-date

Set up your notifications and dont miss out on content that matters to you

BT