BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

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

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

Lire ce contenu en français

Bookmarks

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
Style

BT