PacktLib: Apache Camel Developer's Cookbook

Apache Camel Developer's Cookbook

Credits

About the Authors

Acknowledgments

About the Reviewers

www.PacktPub.com

Preface

Structuring Routes

Introduction

Using Camel in a Java application

Embedding Camel in a Spring application

Using Camel components

Reusing routing logic by connecting routes

Asynchronously connecting routes

Spanning Camel contexts within a single Java process

Using external properties in Camel routes

Reusing endpoints

Reusing routing logic through template routes

Controlling route startup and shutdown

Message Routing

Introduction

Content Based Routing

Filtering out unwanted messages

Wire Tap – sending a copy of the message elsewhere

Multicast – routing the same message to many endpoints

Recipient List – routing a message to a list of endpoints

Throttler – restricting the number of messages flowing to an endpoint

Request-response route sending a one-way message

One-way route waiting on a request-response endpoint

Dynamic Routing – making routing decisions at runtime

Load balancing across a number of endpoints

Routing Slip – routing a message to a fixed list of endpoints

Routing to Your Code

Introduction

Routing messages directly to a Java method

Sending messages directly to a Camel endpoint

Using a Java method as a Predicate

Writing a custom Camel Processor

Mapping the message to method parameters

Writing a custom data marshaller

Writing a custom data type converter

Transformation

Introduction

Transforming using a Simple Expression

Transforming inline with XQuery

Transforming with XSLT

Transforming from Java to XML with JAXB

Transforming from Java to JSON

Transforming from XML to JSON

Parsing comma-separated values (CSV)

Enriching your content with some help from other endpoints

Normalizing messages into a common XML format

Splitting and Aggregating

Introduction

Splitting a message into fragments

Splitting XML messages

Processing split messages in parallel

Aggregating related messages

Aggregating with timeouts

Aggregating with intervals

Processing aggregated messages in parallel

Splitting a message, and processing and gathering responses

Splitting messages and re-aggregating them using different criteria

Parallel Processing

Introduction

Increasing message consumption through multiple endpoint consumers

Spreading the load within a route using a set of threads

Routing a request asynchronously

Using custom thread pools

Using thread pool profiles

Working with asynchronous APIs

Error Handling and Compensation

Introduction

Logging errors

Dead Letter Channel – handling errors later

Retrying an operation

Conditional retry

Customizing each redelivery attempt

Catching exceptions

Marking exceptions as handled

Fine-grained error handling using doTry…doCatch

Defining completion actions

Defining completion actions dynamically

Transactions and Idempotency

Introduction

Preventing duplicate invocation of routing logic

Transactional file consumption

Using transactions with a database

Limiting the scope of a transaction

Rolling back a transaction

Using transactions with messaging

Idempotency inside transactions

Setting up XA transactions over multiple transactional resources

Testing

Introduction

Testing routes defined in Java

Using mock endpoints to verify routing logic

Replying from mock endpoints

Testing routes defined in Spring

Testing routes defined in OSGi Blueprint

Auto-mocking of endpoints

Validating route behavior under heavy load

Unit testing processors and Bean Bindings

Testing routes with fixed endpoints using AOP

Testing routes with fixed endpoints using conditional events

Monitoring and Debugging

Introduction

Logging meaningful steps within your route

Debugging using logging

Throughput logging

Enabling step-by-step tracing in code

Disabling JMX

Configuring JMX

Naming your routes to make it easier to monitor

Adding JMX attributes and operations

Monitoring other systems using the Camel JMX Component

Setting breakpoints in your routes

Security

Introduction

Encrypting configuration properties

Digitally signing and verifying messages

Encrypting and decrypting a message

Encrypting all or parts of an XML message

Authentication and authorization using Spring Security

Web Services

Introduction

Generating the service stubs from a WSDL

Invoking a remote web service from Camel

Implementing a web service with a Camel route

Providing multiple web service operations within a single route

Handling web service faults

Web service proxying

Index