Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Apache Camel Developer's Cookbook
Apache Camel Developer's Cookbook

Apache Camel Developer's Cookbook: 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.

eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Apache Camel Developer's Cookbook

Chapter 2. Message Routing

In this chapter, we will cover the following recipes:

  • 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

Introduction

This chapter explains how to make use of Camel's built-in EIPs (Enterprise Integration Patterns) to write typical integration logic. Once a message is consumed from an endpoint, you will want to make decisions about what steps should be taken to process it (such as routing), and these EIPs provide you with many different message routing options. The EIPs are used within routes defined by the Camel DSLs (Domain Specific Language).

The EIPs are first class constructs within the DSL. As such, your integration logic will be able to more clearly express how the message is being routed–that is, which EIP is being used. The more you can use these EIP DSL statements within your Camel code, versus doing a lot of routing within custom Java processors, the easier it will be for you and others to understand what the Camel route is doing for future maintenance. This is a key value of Camel, so take full advantage of it within your code, and you will find that you have gained...

Content Based Routing

When you need to route messages based on the content of the message, and/or based on the headers or properties associated with the message, using Camel's Content Based Router EIP is a great way to do that.

Content Based Routing

Content Based Routing and Filtering are very similar. A Content Based Router has multiple predicates, and the contained steps are performed on the first predicate that the message matches, or the optional otherwise statement if none matches (similar to an if () {..} else if () {..} else {..} statement in Java).

Camel's Filter EIP tests against a single predicate, executing the contained processing steps only if the message matches that predicate. The equivalent of a Filter in Java would be a single if statement.

In this recipe, we will see how to use a Content Based Router to route a message to one of the several destinations based on the content (the body) of the message.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.routing...

Filtering out unwanted messages

When you need to perform a sequence of steps only when a message matches a certain condition (Predicate), then a Filter is a good option.

Filtering out unwanted messages

Content Based Routing and Filtering are very similar. Filtering processes a message only if it matches the single predicate provided (much like a single if statement).

A Content Based Router routes a message based on the first of the multiple predicates, or the optional otherwise statement if none of the provided predicates matched (similar to an if () {..} else if () {..} else {..} statement in Java).

This recipe will show you how to perform message processing steps only on those messages that match a specified predicate.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.routing.filtering package. The Spring XML files are located under src/main/resources/META-INF/spring and prefixed with filtering.

How to do it...

Create a filter statement followed by a predicate using any of the Camel Expression...

Wire Tap – sending a copy of the message elsewhere

When you want to process the current message in the background (concurrently) to the main route, without requiring a response, the Wire Tap EIP can help. A typical use case for this is logging the message to a backend system. The main thread of execution will continue to process the message through the current route as usual, while Wire Tap allows additional messaging processing to occur outside of the main route.

Wire Tap – sending a copy of the message elsewhere

This recipe will show you how to send a copy of the message to a different endpoint.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.routing.wiretap package. The Spring XML files are located under src/main/resources/META-INF/spring and prefixed with wireTap.

How to do it...

Use the wireTap statement and specify the endpoint URI of where to send a copy of the message.

In the XML DSL, this is written as follows:

<route>
  <from uri="direct:start"/>
  <wireTap uri="mock...

Multicast – routing the same message to many endpoints

When you want to route the same message to a number of endpoints and have them process the message in different ways, the Multicast EIP is a good choice.

This recipe will show you the default, sequential way to use Camel's Multicast EIP. Chapter 6, Parallel Processing, contains a recipe for using Multicast with concurrency (threads).

Getting ready

The Java code for this recipe is located in the org.camelcookbook.routing.multicast package. The Spring XML files are located under src/main/resources/META-INF/spring and prefixed with multicast.

How to do it...

Use the multicast DSL statement, and list the endpoints and processing steps within it.

In the XML DSL, this routing logic is written as:

<route>
  <from uri="direct:start"/>
  <multicast>
    <to uri="mock:first"/>
    <to uri="mock:second"/>
    <to uri="mock:third"/>
  </multicast>
</route...

Recipient List – routing a message to a list of endpoints

When you want to dynamically (at runtime) decide a list of endpoints that an individual message should be sent to, use the Recipient List EIP. This EIP is made up of two phases: deciding where to route the message, and subsequently invoking those route steps. It can be thought of as a dynamic Multicast, and behaves in much the same way.

Recipient List – routing a message to a list of endpoints

This recipe will show you how to route a message to a number of dynamically specified endpoints.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.routing.recipientlist package. The Spring XML files are located under src/main/resources/META-INF/spring and prefixed with recipientList.

How to do it...

Use the recipientList DSL statement, which includes an Expression that tells it where to get, the list of endpoints for routing the message at runtime.

In the XML DSL, this routing logic is written as:

<route>
  <from uri="direct:start"/>
  <setHeader...

Throttler – restricting the number of messages flowing to an endpoint

When you need to limit the number of messages flowing through a route during a specified time period, the Throttler EIP can help. For example, if you have a downstream system that can only handle 10 requests per second, using a Throttler EIP within your route can ensure that you do not exceed that rate.

This recipe will show you how to restrict the number of messages routed to a set of endpoints during a specified time period.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.routing.throttler package. The Spring XML files are located under src/main/resources/META-INF/spring and prefixed with throttler.

How to do it...

In order to use the Throttler, perform the following steps:

  1. You must specify the maximum number of messages to be allowed per time period (defaults to 1,000 ms).

    In the XML DSL, this is specified as an Expression to allow for the maximum rate to be changed at runtime. In this...

Request-response route sending a one-way message

When processing a message in a Request-Response (InOut) route, you sometimes need to send the message to an endpoint, but do not want to receive a response. This recipe shows you how to invoke such an endpoint using the InOnly MEP.

The MEP used can radically alter the behavior of an endpoint. For example, if you invoke a JMS endpoint within a request-response (InOut) route, it will send a message to a queue and set up a listener on a temporary destination waiting for a response; this is known as request-response over messaging. If the consumer of the message on the other side of the queue has not been written to send a response message, your route will wait indefinitely (or as long as the configurable timeout of the component).

This recipe shows how you can alter the MEP temporarily in order to send messages one way in a request-response route.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.routing.changingmep...

Introduction


This chapter explains how to make use of Camel's built-in EIPs (Enterprise Integration Patterns) to write typical integration logic. Once a message is consumed from an endpoint, you will want to make decisions about what steps should be taken to process it (such as routing), and these EIPs provide you with many different message routing options. The EIPs are used within routes defined by the Camel DSLs (Domain Specific Language).

The EIPs are first class constructs within the DSL. As such, your integration logic will be able to more clearly express how the message is being routed–that is, which EIP is being used. The more you can use these EIP DSL statements within your Camel code, versus doing a lot of routing within custom Java processors, the easier it will be for you and others to understand what the Camel route is doing for future maintenance. This is a key value of Camel, so take full advantage of it within your code, and you will find that you have gained more flexibility...

Content Based Routing


When you need to route messages based on the content of the message, and/or based on the headers or properties associated with the message, using Camel's Content Based Router EIP is a great way to do that.

Content Based Routing and Filtering are very similar. A Content Based Router has multiple predicates, and the contained steps are performed on the first predicate that the message matches, or the optional otherwise statement if none matches (similar to an if () {..} else if () {..} else {..} statement in Java).

Camel's Filter EIP tests against a single predicate, executing the contained processing steps only if the message matches that predicate. The equivalent of a Filter in Java would be a single if statement.

In this recipe, we will see how to use a Content Based Router to route a message to one of the several destinations based on the content (the body) of the message.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.routing.contentbasedrouter...

Filtering out unwanted messages


When you need to perform a sequence of steps only when a message matches a certain condition (Predicate), then a Filter is a good option.

Content Based Routing and Filtering are very similar. Filtering processes a message only if it matches the single predicate provided (much like a single if statement).

A Content Based Router routes a message based on the first of the multiple predicates, or the optional otherwise statement if none of the provided predicates matched (similar to an if () {..} else if () {..} else {..} statement in Java).

This recipe will show you how to perform message processing steps only on those messages that match a specified predicate.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.routing.filtering package. The Spring XML files are located under src/main/resources/META-INF/spring and prefixed with filtering.

How to do it...

Create a filter statement followed by a predicate using any of the Camel Expression...

Wire Tap – sending a copy of the message elsewhere


When you want to process the current message in the background (concurrently) to the main route, without requiring a response, the Wire Tap EIP can help. A typical use case for this is logging the message to a backend system. The main thread of execution will continue to process the message through the current route as usual, while Wire Tap allows additional messaging processing to occur outside of the main route.

This recipe will show you how to send a copy of the message to a different endpoint.

Getting ready

The Java code for this recipe is located in the org.camelcookbook.routing.wiretap package. The Spring XML files are located under src/main/resources/META-INF/spring and prefixed with wireTap.

How to do it...

Use the wireTap statement and specify the endpoint URI of where to send a copy of the message.

In the XML DSL, this is written as follows:

<route>
  <from uri="direct:start"/>
  <wireTap uri="mock:tapped"/>
  <to...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • 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.

Description

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.

Who is this book for?

Apache Camel Developer's Cookbook is intended for developers who have some familiarity with Apache Camel and who want a quick lookup reference to practical, proven tips on how to perform common tasks. Every recipe also includes a summary and reference pointers for more details that make it easy for you to get a deeper understanding of the Apache Camel capabilities that you will use day to day.

What you will learn

  • Learn ways to structure your Camel projectsUnderstand common Enterprise Integration Pattern usageTransform your messagesUse Camel s built-in testing frameworkExtend Camel to better interoperate with your existing codeLearn the strategies for Error HandlingUse Camel s parallel processing and threading capabilitiesSecure your Camel integration routesUnderstand ACID Transaction processing within Camel

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Dec 26, 2013
Length: 424 pages
Edition : 1st
Language : English
ISBN-13 : 9781782170310
Vendor :
Apache
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Dec 26, 2013
Length: 424 pages
Edition : 1st
Language : English
ISBN-13 : 9781782170310
Vendor :
Apache
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 83.97
Instant Apache Camel Messaging System
€20.99
Instant Apache Camel Message Routing
€20.99
Apache Camel Developer's Cookbook
€41.99
Total 83.97 Stars icon
Banner background image

Table of Contents

13 Chapters
1. Structuring Routes Chevron down icon Chevron up icon
2. Message Routing Chevron down icon Chevron up icon
3. Routing to Your Code Chevron down icon Chevron up icon
4. Transformation Chevron down icon Chevron up icon
5. Splitting and Aggregating Chevron down icon Chevron up icon
6. Parallel Processing Chevron down icon Chevron up icon
7. Error Handling and Compensation Chevron down icon Chevron up icon
8. Transactions and Idempotency Chevron down icon Chevron up icon
9. Testing Chevron down icon Chevron up icon
10. Monitoring and Debugging Chevron down icon Chevron up icon
11. Security Chevron down icon Chevron up icon
12. Web Services Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.1
(17 Ratings)
5 star 52.9%
4 star 23.5%
3 star 11.8%
2 star 5.9%
1 star 5.9%
Filter icon Filter
Top Reviews

Filter reviews by




Ravindra Godbole Aug 03, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Very useful book for Apache Camel users for practical usage of framework. It provides live examples in Java as well as Spring DSL and list many best practices while authoring routes. A collection of complex routes deployed in various scenarios in the enterprises which are currently using Apache Camel will be great help to readers of the book [ apart from the per topic examples provided ]
Amazon Verified review Amazon
Brennan Apr 27, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Exactly what I was looking for to bootstrap a Camel+AMQ deployment. Easy to find what you're looking for, and shows both regular Java DSL's and Spring integrations.
Amazon Verified review Amazon
SuJo Sep 15, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Wow! What an amazing book to get started with Apache Camel, I've never used this before and found this book immensely helpful. It was a practical read, very organized, and covered everything I expected to learn. The parallel processing was probably my favorite chapter, with error handling in a close 2nd place. The book was easily understood and well worth the $25, which if you catch a sale or one of the specials makes buying more than one book advantageous.Debugging and Security were on point and I'm always critical about these two areas, you need to find bugs and squash them along with maintaining the integrity of the application even on the security side. Overall I felt the book delivered and was not overdone, just enough to get me started while leaving room for growth which I would get into more advanced books for.Publisher Link: https://www.packtpub.com/application-development/apache-camel-developers-cookbook
Amazon Verified review Amazon
Thomas Walzer Jun 11, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
tl;dr: buy nowThis book is essential reading for every serious Apache Camel developer. Its return on investment is great even if you only use a single recipe. But you will be able to use many of them. It greatly reduces the learning curve (and head scratching) and you will find a lot of material not covered anywhere else.This book will not gather dust on a shelf (or in the Amazon cloud), you will use it often.
Amazon Verified review Amazon
Christian Posta Jan 07, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Apache Camel is the de-facto standard java integration library with support for hundreds of components for talking to external systems, implementation of the enterprise integration patterns from the EIP book, all wrapped up in a declarative, expressive DSL. Throw in testing support out of the box, vibrant community, and production support, and you cannot beat it for integration work.Camel in Action is the authoritative book up to this point on understanding and using Apache Camel. This book builds on that foundational knowledge and demonstrates, step-by-step, how to use Camel to solve real world problems. The content is divided into small bite-sized chunks of functionality or recipes that explain how to solve a specific problem in both the XML and Java DSL as well as how it works and things to watch out for.If you just recently learned Camel and are looking for best practices for solving common integration problems, I highly recommend it. It's targeted toward a moderate to advanced leaning set of architects and developers who already have some experience with Camel.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.