You are previewing Apache Camel Developer's Cookbook.
O'Reilly logo
Apache Camel Developer's Cookbook

Book Description

For Apache Camel developers, this is the book you’ll always want to have handy. It’s stuffed full of great recipes that are designed for quick practical application. Expands your Apache Camel abilities immediately.

  • A practical guide to using Apache Camel delivered in dozens of small, useful recipes

  • Written in a Cookbook format that allows you to quickly look up the features you need, delivering the most important steps to perform with a brief follow-on explanation of what’s happening under the covers

  • The recipes cover the full range of Apache Camel usage from creating initial integrations, transformations and routing, debugging, monitoring, security, and more

  • In Detail

    Apache Camel is a de-facto standard for developing integrations in Java, and is based on well-understood Enterprise Integration Patterns. It is used within many commercial and open source integration products. Camel makes common integration tasks easy while still providing the developer with the means to customize the framework when the situation demands it. Tasks such as protocol mediation, message routing and transformation, and auditing are common usages of Camel.

    Apache Camel Developer's Cookbook provides hundreds of best practice tips for using Apache Camel in a format that helps you build your Camel projects. Each tip or recipe provides you with the most important steps to perform along with a summary of how it works, with references to further reading if you need more information. This book is intended to be a reliable information source that is quicker to use than an Internet search.

    Apache Camel Developer's Cookbook is a quick lookup guide that can also be read from cover to cover if you want to get a sense of the full power of Apache Camel. This book provides coverage of the full lifecycle of creating Apache Camel-based integration projects, including the structure of your Camel code and using the most common Enterprise Integration patterns. Patterns like Split/Join and Aggregation are covered in depth in this book.

    Throughout this book, you will be learning steps to transform your data. You will also learn how to perform unit and integration testing of your code using Camel's extensive testing framework, and also strategies for debugging and monitoring your code. Advanced topics like Error Handling, Parallel Processing, Transactions, and Security will also be covered in this book.

    This book provides you with practical tips on using Apache Camel based on years of hands-on experience from hundreds of integration projects.

    Table of Contents

    1. Apache Camel Developer's Cookbook
      1. Table of Contents
      2. Apache Camel Developer's Cookbook
      3. Credits
      4. About the Authors
      5. Acknowledgments
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers and more
          1. Why Subscribe?
          2. Free Access for Packt account holders
          3. Instant Updates on New Packt Books
      8. Preface
        1. What is Camel?
        2. Camel Concepts
        3. The Camel DSL
        4. What this book covers
        5. What you need for this book
        6. Who this book is for
        7. Conventions
        8. Reader feedback
        9. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 1. Structuring Routes
        1. Introduction
        2. Using Camel in a Java application
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Embedding Camel in a Spring application
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Using Camel components
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Reusing routing logic by connecting routes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Asynchronously connecting routes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Spanning Camel contexts within a single Java process
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Using external properties in Camel routes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Reusing endpoints
          1. Getting ready
          2. How to do it...
        10. Reusing routing logic through template routes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        11. Controlling route startup and shutdown
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      10. 2. Message Routing
        1. Introduction
        2. Content Based Routing
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Filtering out unwanted messages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Wire Tap – sending a copy of the message elsewhere
          1. Getting ready
          2. How to do it...
          3. How it works...
            1. Deep copying of the exchange
          4. There's more...
          5. See also
        5. Multicast – routing the same message to many endpoints
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Recipient List – routing a message to a list of endpoints
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Throttler – restricting the number of messages flowing to an endpoint
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Request-response route sending a one-way message
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. One-way route waiting on a request-response endpoint
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Dynamic Routing – making routing decisions at runtime
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        11. Load balancing across a number of endpoints
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        12. Routing Slip – routing a message to a fixed list of endpoints
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      11. 3. Routing to Your Code
        1. Introduction
        2. Routing messages directly to a Java method
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Sending messages directly to a Camel endpoint
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Using a Java method as a Predicate
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Writing a custom Camel Processor
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Mapping the message to method parameters
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Writing a custom data marshaller
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Writing a custom data type converter
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      12. 4. Transformation
        1. Introduction
        2. Transforming using a Simple Expression
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Transforming inline with XQuery
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Transforming with XSLT
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Transforming from Java to XML with JAXB
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Transforming from Java to JSON
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Transforming from XML to JSON
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Parsing comma-separated values (CSV)
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Enriching your content with some help from other endpoints
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Normalizing messages into a common XML format
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      13. 5. Splitting and Aggregating
        1. Introduction
        2. Splitting a message into fragments
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Splitting XML messages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Processing split messages in parallel
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Aggregating related messages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Aggregating with timeouts
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        7. Aggregating with intervals
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Processing aggregated messages in parallel
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Splitting a message, and processing and gathering responses
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Splitting messages and re-aggregating them using different criteria
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      14. 6. Parallel Processing
        1. Introduction
        2. Increasing message consumption through multiple endpoint consumers
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Spreading the load within a route using a set of threads
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Routing a request asynchronously
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Using custom thread pools
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Using thread pool profiles
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Working with asynchronous APIs
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      15. 7. Error Handling and Compensation
        1. Introduction
        2. Logging errors
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Dead Letter Channel – handling errors later
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Retrying an operation
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Conditional retry
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Customizing each redelivery attempt
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Catching exceptions
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Marking exceptions as handled
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Fine-grained error handling using doTry…doCatch
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Defining completion actions
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        11. Defining completion actions dynamically
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      16. 8. Transactions and Idempotency
        1. Introduction
        2. Preventing duplicate invocation of routing logic
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Transactional file consumption
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Using transactions with a database
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Limiting the scope of a transaction
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        6. Rolling back a transaction
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        7. Using transactions with messaging
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Idempotency inside transactions
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Setting up XA transactions over multiple transactional resources
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      17. 9. Testing
        1. Introduction
        2. Testing routes defined in Java
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Using mock endpoints to verify routing logic
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Replying from mock endpoints
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Testing routes defined in Spring
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Testing routes defined in OSGi Blueprint
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Auto-mocking of endpoints
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
        8. Validating route behavior under heavy load
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Unit testing processors and Bean Bindings
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Testing routes with fixed endpoints using AOP
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        11. Testing routes with fixed endpoints using conditional events
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      18. 10. Monitoring and Debugging
        1. Introduction
        2. Logging meaningful steps within your route
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Debugging using logging
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Throughput logging
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Enabling step-by-step tracing in code
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Disabling JMX
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Configuring JMX
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        8. Naming your routes to make it easier to monitor
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        9. Adding JMX attributes and operations
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        10. Monitoring other systems using the Camel JMX Component
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        11. Setting breakpoints in your routes
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      19. 11. Security
        1. Introduction
        2. Encrypting configuration properties
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Digitally signing and verifying messages
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Encrypting and decrypting a message
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Encrypting all or parts of an XML message
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Authentication and authorization using Spring Security
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      20. 12. Web Services
        1. Introduction
        2. Generating the service stubs from a WSDL
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        3. Invoking a remote web service from Camel
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        4. Implementing a web service with a Camel route
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        5. Providing multiple web service operations within a single route
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Handling web service faults
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Web service proxying
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
      21. Index