Camel in Action, Second Edition
Claus Ibsen and Jonathan Anstey
  • MEAP began July 2015
  • Publication in December 2017 (estimated)
  • ISBN 9781617292934
  • 960 pages (estimated)
  • printed in black & white

GET MORE WITH MANNING

An eBook copy of the previous edition, Camel in Action (First Edition), is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.


Camel in Action, Second Edition is the most complete Camel book on the market. This updated tutorial is full of small examples showing how to work with the integration patterns. It starts with core concepts like sending, receiving, routing, and transforming data. It then shows you the entire lifecycle and goes in depth on how to test, deal with errors, scale, deploy, and monitor your app and even how to build custom tooling - details you can find only in the Camel code itself. Written by core developers of Camel and the authors of the first edition, this book distills their experience and practical insights so that you can tackle integration tasks like a pro.

Table of Contents detailed table of contents

Part 1: First Steps

1. Meeting Camel

1.1. Introducing Camel

1.1.1. What is Camel?

1.1.2. Why use Camel?

1.2. Getting started

1.2.1. Getting Camel

1.2.2. Your first Camel ride

1.3. Camel's message model

1.3.1. Message

1.3.2. Exchange

1.4. Camel's architecture

1.4.1. Architecture from 10,000 feet

1.4.2. Camel concepts

1.5. Your first Camel ride, revisited

1.6. Summary

2. Routing with Camel

2.1. Introducing Rider Auto Parts

2.2. Understanding endpoints

2.2.1. Consuming from an FTP endpoint

2.2.2. Sending to a JMS endpoint

2.3. Creating routes in Java

2.3.1. Using the RouteBuilder

2.3.2. The Java DSL

2.4. Defining routes in XML

2.4.1. Bean injection and Spring

2.4.2. The XML DSL

2.4.3. Using Camel and Spring

2.5. Endpoints revisited

2.5.1. Sending to dynamic endpoints

2.5.2. Using property placeholders in endpoint URIs

2.5.3. Using raw values in endpoint URIs

2.5.4. Referencing registry beans in endpoint URIs

2.6. Routing and EIPs

2.6.1. Using a content-based router

2.6.2. Using message filters

2.6.3. Using multicasting

2.6.4. Using recipient lists

2.6.5. Using the wireTap method

2.7. Summary and best practices

Part 2: Core Camel

3. Transforming data with Camel

3.1. Data transformation overview

3.1.1. Data transformation with Camel

3.2. Transforming data using EIPs and Java

3.2.1. Using the Message Translator EIP

3.2.2. Using the Content Enricher EIP

3.3. Transforming XML

3.3.1. Transforming XML with XSLT

3.3.2. Transforming XML with object marshaling

3.4. Transforming with data formats

3.4.1. Data formats provided with Camel

3.4.2. Using Camel's CSV data format

3.4.3. Using Camel's Bindy data format

3.4.4. Using Camel's JSON data format

3.4.5. Configuring Camel data formats

3.4.6. Writing your own data format

3.5. Transforming with templates

3.5.1. Using Apache Velocity

3.6. About Camel type converters

3.6.1. How the Camel type—converter mechanism works

3.6.2. Using Camel type converters

3.6.3. Writing your own type converter

3.7. Summary and best practices

4. Using beans with Camel

4.1. Using beans the hard way and the easy way

4.1.1. Invoking a bean from pure Java

4.1.2. Invoking a bean defined in XML DSL

4.1.3. Using beans the easy way

4.2. The Service Activator pattern

4.3. Camel's bean registries

4.3.1. JndiRegistry

4.3.2. SimpleRegistry

4.3.3. ApplicationContextRegistry

4.3.4. OsgiServiceRegistry and BlueprintContainerRegistry

4.3.5. CdiBeanRegistry

4.4. Selecting bean methods

4.4.1. How Camel selects bean methods

4.4.2. Camel's method-selection algorithm

4.4.3. Some method-selection examples

4.4.4. Potential method-selection problems

4.4.5. Method selection using type matching

4.5. Bean parameter binding

4.5.1. Binding with multiple parameters

4.5.2. Binding using built-in types

4.5.3. Binding using Camel annotations

4.5.4. Binding using Camel language annotations

4.5.5. Parameter binding using method name with signature

4.6. Using beans as predicates and expressions

4.6.1. Using beans as predicates in routes

4.6.2. Using beans as expressions in routes

4.7. Summary and best practices

5. Enterprise integration patterns

5.1. Introducing enterprise integration patterns

5.1.1. The Aggregator and Splitter EIPs

5.1.2. The Routing Slip and Dynamic Router EIPs

5.1.3. The Load Balancer EIP

5.2. The Aggregator EIP

5.2.1. Introducing the Aggregator EIP

5.2.2. Completion conditions for the Aggregator

5.2.3. Using persistence with the Aggregator

5.2.4. Using recovery with the Aggregator

5.3. The Splitter EIP

5.3.1. Using the Splitter

5.3.2. Using beans for splitting

5.3.3. Splitting big messages

5.3.4. Aggregating split messages

5.3.5. When errors occur during splitting

5.4. The Routing Slip EIP

5.4.1. Using the Routing Slip EIP

5.4.2. Using a bean to compute the routing slip header

5.4.3. Using an Expression as the routing slip

5.4.4. Using @RoutingSlip annotation

5.5. The Dynamic Router EIP

5.5.1. Using the Dynamic Router

5.5.2. Using the @DynamicRouter annotation

5.6. The Load Balancer EIP

5.6.1. Introducing the Load Balancer EIP

5.6.2. Load-balancing strategies

5.6.3. Using the failover load balancer

5.6.4. Using a custom load balancer

5.7. Summary and best practices

6. Using components

6.1. Overview of Camel components

6.1.1. Manually adding components

6.1.2. Autodiscovering components

6.2. Working with files (File and FTP components)

6.2.1. Reading and writing files with the File component

6.2.2. Accessing remote files with the FTP component

6.3. Asynchronous messaging (JMS component)

6.3.1. Sending and receiving messages

6.3.2. Request-reply messaging

6.3.3. Message mappings

6.4. Networking (Netty4 component)

6.4.1. Using Netty for network programming

6.4.2. Using custom codecs

6.5. Working with databases (JDBC and JPA components)

6.5.1. Accessing data with the JDBC component

6.5.2. Persisting objects with the JPA component

6.6. In-memory messaging (Direct, Direct-VM, SEDA, and VM components)

6.6.1. Synchronous messaging with the Direct and Direct-VM components

6.6.2. Asynchronous messaging with SEDA and VM

6.7. Automating tasks (Scheduler and Quartz2 components)

6.7.1. Using the Scheduler component

Part 3: Developing and testing

7. Microservices

7.1. Microservices Overview

7.1.1. Microservices Characteristics

7.2. Running Camel microservices

7.2.1. Standalone Camel as microservice

7.2.2. CDI Camel as microservice

7.2.3. WildFly Swarm with Camel as microservice

7.2.4. Spring Boot with Camel as microservice

7.2.5. Using Vert.x to build microservices

7.2.6. Using Camel together with Vert.X

7.3. Calling other microservices

7.3.1. Recommendation prototype

7.3.2. Shopping cart prototype

7.3.3. Rules and Inventory prototypes

7.3.4. Rating prototype

7.3.5. Putting all the microservices together

7.4. Designing for failures

7.4.1. Using Retry Pattern to handle failures

7.4.2. Using Retry Pattern without Camel

7.4.3. Using Circuit Breaker to handle failures

7.4.4. Netflix Hystrix

7.4.5. Using Hystrix with Camel

7.4.6. Configuring Hystrix

7.4.7. Bulkhead pattern

7.4.8. Calling other microservice with fault tolerance

7.4.9. Using Camel Hystrix with Spring Boot

7.4.10. The Hystrix Dashboard

7.5. Summary and best practices

8. Developing Camel projects

8.1. Managing projects with Maven

8.1.1. Using Camel Maven archetypes

8.1.2. Camel Maven dependencies

8.2. Using Camel in Eclipse

8.2.1. Starting a new Camel project

8.2.2. Debugging an issue with your new Camel project

8.3. Developing custom components

8.3.1. Setting up a new Camel component

8.3.2. Diving into the implementation

8.4. Generating components with the API component framework

8.4.1. Generating the skeleton API project

8.4.2. Configuring the camel-api-component-maven-plugin

8.4.3. Advanced configuration options

8.4.4. Implementing remaining functionality

8.5. Developing data formats

8.5.1. Generating the skeleton data format project

8.5.2. Writing the custom data format

8.6. Developing interceptors

8.6.1. Creating an InterceptStrategy

8.7. Summary and best practices

9. Testing

9.1. Introducing the Camel Test Kit

9.1.1. The Camel JUnit extensions

9.1.2. Using camel-test to test Java Camel routes

9.1.3. Unit testing an existing RouteBuilder class

9.2. Testing Camel with Spring, Blueprint, and CDI

9.2.1. Camel testing with Spring XML

9.2.2. Camel testing with Spring Java Config

9.2.3. Camel testing with Spring Boot

9.2.4. Camel testing with OSGi Blueprint XML

9.2.5. Camel testing with CDI

9.2.6. Camel testing with WildFly

9.3. Using the Mock component

9.3.1. Introducing the Mock component

9.3.2. Unit testing with the Mock component

9.3.3. Verifying that the correct message arrived

9.3.4. Using expressions with mocks

9.3.5. Testing the ordering of messages

9.3.6. Using mocks to simulate real components

9.4. Simulating errors

9.4.1. Simulating errors using a processor

9.4.2. Simulating errors using mocks

9.4.3. Simulating errors using interceptors

9.4.4. Using adviceWith to add interceptors to an existing route

9.4.5. Using adviceWith to manipulate routes for testing

9.4.6. Using weave with advice with to amend routes

9.5. Camel integration testing

9.5.1. Integration testing

9.5.2. Using NotifyBuilder

9.6. Using third party testing libraries

9.6.1. Using Arquillian to test Camel applications

9.6.2. Using Pax-Exam to test Camel applications

9.6.3. Using Citrus Framework to test Camel applications

9.6.4. Other Testing Libraries

9.7. Summary and best practices

Part 4: Going further with Camel

10. RESTful and SOAP web services

10.1. Restful services

10.1.1. The principle of an RESTful API

10.1.2. Using JAX-RS with REST services

10.1.3. Using Camel in an existing JAX-RS application

10.1.4. Using camel-reslet with REST services

10.1.5. Using camel-cxfrs with REST services

10.2. The Camel Rest DSL

10.2.1. A quick example of the Rest DSL

10.2.2. How the Rest DSL works

10.2.3. Supported components for the Rest DSL

10.2.4. Configuring Rest DSL

10.2.5. Using XML and JSon data formats with Rest DSL

10.3. API Documentation using Swagger

10.3.1. Using Swagger with JAX-RS Rest services

10.3.2. Using Swagger with Rest DSL

10.3.3. Documenting Rest DSL services

10.3.4. Documenting input, output and error codes

10.3.5. Configuring API documentation

10.3.6. Using CORS and Swagger web console

10.4. Web services

10.4.1. Configuring CXF

10.4.2. Using a contract-first approach

10.4.3. Using a code-first approach

10.5. Summary and best practices

11. Error Handling

11.1. Understanding error handling

11.1.1. Where Camel’s error handling applies

11.2. Error handlers in Camel

11.2.1. The default error handler

11.2.2. The dead letter channel error handler

11.2.3. The transaction error handler

11.2.4. The no error handler

11.2.5. The logging error handler

11.2.6. Features of the error handlers

11.3. Using error handlers with redelivery

11.3.1. An error-handling use case

11.3.2. Using redelivery

11.3.3. Using the DefaultErrorHandler with redelivery

11.3.4. Error handlers and scopes

11.3.5. Reusing context scoped error handlers

11.3.6. Handling faults

11.4. Using exception policies

11.4.1. Understanding how onException catches exceptions

11.4.2. Understanding how onException works with redelivery

11.4.3. Understanding how onException can handle exceptions

11.4.4. Custom exception handling

11.4.5. New exception while handling exception

11.4.6. Ignoring exceptions

11.4.7. Implementing an error handler solution

11.4.8. Bridging the consumer with Camel’s error handler

11.5. Other error-handling features

11.5.1. Using onWhen

11.5.2. Using onRedeliver

11.5.3. Using retryWhile

11.6. Summary and best practices

12. Transactions and Idempotency

12.1. Why use transactions?

12.1.1. The Rider Auto Parts partner integration application

12.1.2. Setting up the JMS broker and the database

12.1.3. The story of the lost message

12.2. Transaction basics

12.2.1. About Spring’s transaction support

12.2.2. Adding transactions

12.2.3. Testing transactions

12.3. The Transactional Client EIP

12.3.1. Using local transactions

12.3.2. Using global transactions

12.3.3. Transaction starting from a database resource

12.3.4. Transaction redeliveries

12.3.5. Transaction propagations

12.3.6. Using transactions with multiple routes

12.3.7. Using different transaction propagations

12.3.8. Returning a custom response when a transaction fails

12.4. Compensating for unsupported transactions

12.4.1. Introducing UnitOfWork

12.4.2. Using Synchronization callbacks

12.4.3. Using onCompletion

12.5. Idempotency

12.5.1. Idempotent Consumer EIP

12.5.2. Idempotent Repositories

12.5.3. Clustered idempotent repository

12.6. Summary and best practices

13. Parallel processing

13.1. Introducing concurrency

13.1.1. Running the example without concurrency

13.1.2. Using concurrency

13.2. Using thread pools

13.2.1. Understanding thread pools in Java

13.2.2. Camel thread pool profiles

13.2.3. Creating custom thread pools

13.2.4. Using ExecutorServiceStrategy

13.3. Parallel processing with EIPs

13.3.1. Using concurrency with the Threads EIP

13.3.2. Using concurrency with the Multicast EIP

13.3.3. Using concurrency with the Wire Tap EIP

13.4. The asynchronous routing engine

13.4.1. Hitting the scalability limit

13.4.2. Scalability in Camel

13.4.3. Components supporting asynchronous processing

13.4.4. Asynchronous API

13.4.5. Writing a custom asynchronous component

13.4.6. Potential issues when using an asynchronous component

13.4.7. Dangers with blocked threads

13.5. Summary and best practices

14. Securing Camel

14.1. Securing your configuration

14.1.1. Encrypting configuration

14.1.2. Decrypting configuration

14.2. Web service security

14.2.1. Authentication in web services

14.2.2. Authenticating web services using JAAS

14.3. Payload security

14.3.1. Digital signatures

14.3.2. Payload encryption

14.4. Transport security

14.5. Route authentication and authorization

14.6. Summary and best practices

Part 5: Running and managing Camel

15. Running and deploying Camel

15.1. Starting Camel

15.1.1. How Camel starts

15.1.2. Camel startup options

15.1.3. Ordering routes

15.1.4. Disabling autostartup

15.2. Starting and stopping routes at runtime

15.2.1. Using CamelContext to start and stop routes at runtime

15.2.2. Using RoutePolicy to start and stop routes at runtime

15.3. Shutting down Camel

15.3.1. Graceful shutdown

15.4. Deploying Camel

15.4.1. Embedded in a Java application

15.4.2. Embedded in a web application

15.4.3. Embedded in WildFly

15.5. Camel and OSGi

15.5.1. Setting up Maven to generate an OSGi bundle

15.5.2. Installing and running Apache Karaf

15.5.3. Using a Blueprint-based Camel route

15.5.4. Deploying the example

15.5.5. Using a managed service factory to spin up route instances

15.6. Camel and CDI

15.6.1. WildFly deployment

15.6.2. Karaf deployment

15.7. Summary and best practices

16. Management and Monitoring

16.1. Monitoring Camel

16.1.1. Checking health at the network level

16.1.2. Checking health level at the JVM level

16.1.3. Checking health at the application level

16.2. Using JMX with Camel

16.2.1. Using JConsole to manage Camel

16.2.2. Using JConsole to remotely manage Camel

16.2.3. Using Jolokia to manage Camel

16.3. Tracking application activity

16.3.1. Using log files

16.3.2. Using core logs

16.3.3. Using custom logging

16.3.4. Using Tracer

16.3.5. Using notifications

16.4. Managing Camel applications

16.4.1. Managing Camel application lifecycles

16.4.2. Using Jolokia and hawtio to manage Camel lifecycles

16.4.3. Using Camel commands to manage Camel

16.4.4. Using controlbus to manage Camel

16.5. The Camel management API

16.5.1. Accessing the Camel management API using Java

16.5.2. Using Camel management API from within Camel

16.5.3. Performance Statistics

16.5.4. Management enable custom Camel components

16.5.5. Management enable custom Java beans

16.6. Summary and best practices

17. Clustering

17.1. Clustered HTTP

17.2. Clustered Camel routes

17.2.1. Clustered active/passive mode using Hazelcast

17.2.2. Clustered active/passive mode using Consul

17.2.3. Clustered active/passive mode using ZooKeeper

17.3. Clustered JMS

17.3.1. Client side clustering with JMS and ActiveMQ

17.4. Clustered Kafka

17.4.1. Kafka consumer offset

17.4.2. Crashing a JVM with a running Kafka consumer

17.5. Clustering caches

17.5.1. Clustered cache using Hazelcast

17.5.2. Clustering cache using JCache and Infinispan

17.6. Using clustered scheduling

17.6.1. Clustered scheduling using Quartz

17.7. Summary and best practices

Part 6: Out in the wild

18. Microservices with Docker and Kubernetes

18.1. Getting started with Camel on Docker

18.1.1. Building and running Camel microservices locally

18.1.2. Building and running Camel microservices using Docker

18.1.3. Building Docker Image using Docker Maven Plugin

18.1.4. Run Java Microservices on Docker

18.2. Getting Started with Kubernetes

18.2.1. Installing Minikube

18.2.2. Starting Minikube

18.3. Running Camel and other applications in Kubernetes

18.3.1. Run applications using kubctl

18.3.2. Calling a service running inside Kubernetes cluster

18.3.3. Run Java applications in Kubernetes using Maven tooling

18.3.4. Java microservices calling each other in the cluster

18.3.5. Debugging Java applications in Kubernetes

18.4. Understanding Kubernetes

18.4.1. Introducing Kubernetes

18.4.2. Kubernetes Architecture

18.4.3. Essential Kubernetes Concepts

18.5. Building resilient Camel microservices on Kubernetes

18.5.1. Scaling up microservices

18.5.2. Using readiness and liveness probes

18.5.3. Dealing with failures calling services in Kubernetes

18.6. fabric8, helm and OpenShift

18.6.1. About fabric8

18.6.2. Installing fabric8 console

18.6.3. Kubernetes Helm

18.6.4. OpenShift

18.7. Summary and best practices

19. Camel tooling

19.1. Camel Editors

19.1.1. JBoss Tools for Apache Camel

19.1.2. fabric8 Camel editor

19.1.3. Camel Validation using Maven

19.2. Camel Catalog - The information goldmine

19.2.1. Developing custom tooling using the camel-catalog

19.2.2. Camel tooling with Karaf

19.3. hawtio - A web console for Camel and Java applications

19.3.1. Overview of hawtio functionality

19.3.2. Debugging Camel routes using hawtio

19.3.3. Building hawtio plugins

19.4. Summary and best practices

20. Camel and IoT

20.1. The Internet Of Things shopping list

20.1.1. Raspberry Pi

20.1.2. SD Card for Raspberry Pi

20.1.3. Power bank for Raspberry Pi

20.1.4. Camera for Raspberry Pi

20.1.5. TI SensorTag

20.2. The Internet Of Things architecture

20.3. Why Camel is a right choice for The Internet Of Things?

20.3.1. Components

20.3.2. Data formats

20.3.3. Redelivery

20.3.4. Throttling

20.3.5. Content based routing

20.3.6. Client side load balancing

20.3.7. Control bus

20.4. Gateway to a data center connectivity

20.4.1. AMQP

20.4.2. MQTT

20.4.3. REST/HTTP

20.5. Camel and Eclipse Kura

20.5.1. Starting Kura in emulator mode

20.5.2. Defining Camel routes using Kura web UI

20.5.3. Next steps with Camel and Kura

20.6. Next steps with Camel and Internet Of Things

20.6.1. Eclipse Kapua

20.6.2. LWM2M and Eclipse Leshan project

20.6.3. Eclipse Hono

21. Reactive Camel

21.1. Using Reactive Streams with Camel

21.1.1. Reactive flow control with back pressure

21.1.2. First steps with Reactive Streams

21.1.3. Using Camel with Reactive Streams

21.1.4. Controlling back pressure from producer side

21.1.5. Controlling back pressure from consumer side

21.2. Using Vert.x with Camel

21.2.1. Building a dong simulator using Vert.x

21.2.2. Using Camel together with Vert.x

21.2.3. Summary of using Camel with Vert.x for microservices

21.3. Summary and best practices

Appendixes

Appendix A: Simple, the expression language

A.1. Introducing Simple

A.2. Syntax

A.3. Built-in variables

A.4. Built-in functions

A.5. Built-in file variables

A.6. Built-in operators

A.6.1. Combining expressions

A.7. The OGNL feature

A.8. Using Simple from custom Java code

A.9. Summary

Appendix B: The Camel community

B.1. Apache Camel website

B.2. JIRA, mailing lists, and IRC

B.3. Camel at GitHub

B.4. Camel at Stack Overflow

B.5. Commercial Camel Offerings

B.6. Camel Tooling

B.7. Camel-extra project

B.8. Camel quick reference card

B.9. Becoming a Camel committer

B.10. Other resources

About the Technology

Apache Camel is a Java library that lets you implement the standard enterprise integration patterns in a few lines of code. With a concise but sophisticated DSL, you snap integration logic into your app, Lego-style, using Java, XML, CDI, Groovy, or Scala. Camel supports over 160 common transports including HTTP, REST, JDBC, JMS, Web Services, and SaaS connectors.

What's inside

  • Revised to reflect the most recent release of Camel
  • New chapters on security, clustering, cloud integration, docker, and kubernetes
  • How to build Camel microservices with Spring Boot, Vert.x, and standalone
  • Valuable examples in Java and XML
  • Explanations of complex patterns
  • Error handling, testing, deploying, managing, and running Camel
  • Accessible to beginners, useful to experts

About the reader

Readers should have basic Java skills.

About the authors

Claus Ibsen is a principal engineer working for Red Hat specializing in cloud and integration. He has worked on Apache Camel for the last seven years where he heads the project. He is also heavily involved with fabric8 and hawtio projects, especially with functionality that involves Camel. Claus lives in Sweden near Malmo with his wife and dog.

Jonathan Anstey is a principal engineer at Red Hat working on open source integration technologies. One of the many projects Jon contributes to is Apache Camel. When he is not hacking on open source he likes to spend time with his wife and two kids in Paradise, Newfoundland.


Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
Buy
MEAP combo $69.99 pBook + eBook + liveBook
MEAP eBook $55.99 pdf + ePub + kindle + liveBook

FREE domestic shipping on three or more pBooks