Camel in Action

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Apache Camel is a Java framework 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, or Scala. Camel supports over 80 common transports such as HTTP, REST, JMS, and Web Services.Camel in Action is a Camel tutorial 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 even monitor your app— details you can find only in the Camel code itself. Written by the developers of Camel, this book distills their experience and practical insights so that you can tackle integration tasks like a pro. What’s Inside: Valuable examples in Java and XML Explanations of complex patterns Error handling, testing, deploying, managing, and running Camel Accessible to beginners, useful to experts

Author(s): Claus Ibsen, Jonathan Anstey
Publisher: Manning Publications
Year: 2011

Language: English
Commentary: 1181365598
Pages: 550
Tags: Библиотека;Компьютерная литература;Java;

Camel in Action......Page 1
brief contents......Page 8
contents......Page 10
foreword......Page 18
foreword......Page 20
preface......Page 22
acknowledgments......Page 24
Jon......Page 25
Roadmap......Page 26
Who should read this book......Page 27
Author Online......Page 28
about the cover illustration......Page 30
about the authors......Page 32
First steps......Page 34
Meeting Camel......Page 36
1.1.1 What is Camel?......Page 37
1.1.2 Why use Camel?......Page 38
1.2.1 Getting Camel......Page 41
1.2.2 Your first Camel ride......Page 42
1.3.1 Message......Page 46
1.3.2 Exchange......Page 47
1.4.1 Architecture from 10,000 feet......Page 48
1.4.2 Camel concepts......Page 49
1.5 Your first Camel ride, revisited......Page 53
1.6 Summary......Page 54
Routing with Camel......Page 55
2.1 Introducing Rider Auto Parts......Page 56
2.2.1 Working with files over FTP......Page 57
2.2.2 Sending to a JMS queue......Page 59
2.3 Creating routes in Java......Page 61
2.3.1 Using the RouteBuilder......Page 62
2.3.2 The Java DSL......Page 63
2.4.1 Bean injection and Spring......Page 67
2.4.2 The Spring DSL......Page 70
2.4.3 Using Camel and Spring......Page 73
2.5 Routing and EIPs......Page 76
2.5.1 Using a content-based router......Page 77
2.5.2 Using message filters......Page 82
2.5.3 Using multicasting......Page 83
2.5.4 Using recipient lists......Page 85
2.5.5 Using the wireTap method......Page 88
2.6 Summary and best practices......Page 90
Core Camel......Page 92
Transforming data with Camel......Page 94
3.1.1 Data transformation with Camel......Page 95
3.2.1 Using the Message Translator EIP......Page 96
3.2.2 Using the Content Enricher EIP......Page 103
3.3.1 Transforming XML with XSLT......Page 106
3.3.2 Transforming XML with object marshaling......Page 108
3.4 Transforming with data formats......Page 110
3.4.1 Data formats provided with Camel......Page 111
3.4.2 Using Camel’s CSV data format......Page 112
3.4.3 Using Camel’s Bindy data format......Page 113
3.4.4 Using Camel’s JSON data format......Page 116
3.4.5 Configuring Camel data formats......Page 117
3.4.6 Writing your own data format......Page 118
3.5 Transforming with templates......Page 119
3.5.1 Using Apache Velocity......Page 120
3.6.1 How the Camel type-converter mechanism works......Page 121
3.6.3 Writing your own type converter......Page 123
3.7 Summary and best practices......Page 125
Using beans with Camel......Page 126
4.1.1 Invoking a bean from pure Java......Page 127
4.1.2 Invoking a bean defined in Spring......Page 128
4.1.3 Using beans the easy way......Page 129
4.2 The Service Activator pattern......Page 130
4.3 Camel’s bean registries......Page 131
4.3.1 SimpleRegistry......Page 133
4.3.3 ApplicationContextRegistry......Page 134
4.3.4 OsgiServiceRegistry......Page 135
4.4 Selecting bean methods......Page 136
4.4.1 How Camel selects bean methods......Page 137
4.4.2 Camel’s method-selection algorithm......Page 138
4.4.3 Some method-selection examples......Page 140
4.4.4 Potential method-selection problems......Page 142
4.5 Bean parameter binding......Page 144
4.5.1 Binding with multiple parameters......Page 145
4.5.2 Binding using built-in types......Page 146
4.5.3 Binding using Camel annotations......Page 147
4.5.4 Binding using Camel language annotations......Page 148
4.6 Summary and best practices......Page 152
Error handling......Page 153
5.1.1 Recoverable and irrecoverable errors......Page 154
5.1.2 Where Camel’s error handling applies......Page 156
5.2 Error handlers in Camel......Page 157
5.2.1 The default error handler......Page 158
5.2.2 The dead letter channel error handler......Page 159
5.2.6 Features of the error handlers......Page 161
5.3.1 An error-handling use case......Page 162
5.3.2 Using redelivery......Page 163
5.3.3 Error handlers and scopes......Page 168
5.3.4 Handling faults......Page 170
5.4 Using exception policies......Page 171
5.4.1 Understanding how onException catches exceptions......Page 172
5.4.2 Understanding how onException works with redelivery......Page 175
5.4.3 Understanding how onException can handle exceptions......Page 176
5.4.4 Custom exception handling......Page 179
5.4.5 Ignoring exceptions......Page 181
5.4.6 Implementing an error handler solution......Page 182
5.5.1 Using onWhen......Page 183
5.5.2 Using onRedeliver......Page 184
5.5.3 Using retryWhile......Page 185
5.6 Summary and best practices......Page 186
Testing with Camel......Page 187
6.1.1 The Camel JUnit extensions......Page 188
6.1.3 Unit testing with the CamelTestSupport class......Page 189
6.1.5 Unit testing with the SpringCamelTestSupport class......Page 192
6.1.6 Unit testing in multiple environments......Page 194
6.2 Using the Mock component......Page 199
6.2.2 Unit testing with the Mock component......Page 200
6.2.3 Verifying that the correct message arrived......Page 202
6.2.4 Using expressions with mocks......Page 203
6.2.5 Testing the ordering of messages......Page 207
6.2.6 Using mocks to simulate real components......Page 208
6.3.1 Simulating errors using a processor......Page 211
6.3.3 Simulating errors using interceptors......Page 213
6.4.1 Integration testing......Page 216
6.4.2 Using NotifyBuilder......Page 218
6.5 Summary and best practices......Page 220
Understanding components......Page 221
7.1 Overview of Camel components......Page 222
7.1.2 Autodiscovering components......Page 223
7.2 Working with files (File and FTP components)......Page 225
7.2.1 Reading and writing files with the File component......Page 226
7.2.2 Accessing remote files with the FTP component......Page 229
7.3 Asynchronous messaging (JMS component)......Page 230
7.3.1 Sending and receiving messages......Page 233
7.3.2 Request-reply messaging......Page 234
7.3.3 Message mappings......Page 235
7.4 Web services (CXF component)......Page 238
7.4.1 Configuring CXF......Page 239
7.4.2 Using a contract-first approach......Page 242
7.4.3 Using a code-first approach......Page 248
7.5 Networking (MINA component)......Page 249
7.5.1 Using MINA for network programming......Page 250
7.5.2 Using custom codecs......Page 252
7.6.1 Accessing data with the JDBC component......Page 254
7.6.2 Persisting objects with the JPA component......Page 257
7.7.1 Synchronous messaging with the Direct component......Page 262
7.7.2 Asynchronous messaging with SEDA and VM......Page 263
7.8.1 Using the Timer component......Page 265
7.8.2 Enterprise scheduling with Quartz......Page 266
7.9 Summary and best practices......Page 268
Enterprise integration patterns......Page 270
8.1.1 The Aggregator and Splitter EIPs......Page 271
8.2 The Aggregator EIP......Page 272
8.2.1 Introducing the Aggregator EIP......Page 273
8.2.2 Completion conditions for the Aggregator......Page 276
8.2.3 Using persistence with the Aggregator......Page 281
8.2.4 Using recovery with the Aggregator......Page 284
8.3 The Splitter EIP......Page 288
8.3.1 Using the Splitter......Page 289
8.3.2 Using beans for splitting......Page 291
8.3.3 Splitting big messages......Page 293
8.3.4 Aggregating split messages......Page 295
8.3.5 When errors occur during splitting......Page 297
8.4 The Routing Slip EIP......Page 299
8.4.2 Using a bean to compute the routing slip header......Page 300
8.4.3 Using an Expression as the routing slip......Page 301
8.4.4 Using @RoutingSlip annotation......Page 302
8.5.1 Using the Dynamic Router......Page 303
8.5.2 Using the @DynamicRouter annotation......Page 304
8.6.1 Introducing the Load Balancer EIP......Page 305
8.6.2 Load-balancing strategies......Page 307
8.6.3 Using the failover load balancer......Page 308
8.6.4 Using a custom load balancer......Page 311
8.7 Summary and best practices......Page 313
Out in the wild......Page 314
Using transactions......Page 316
9.1.1 The Rider Auto Parts partner integration application......Page 317
9.1.2 Setting up the JMS broker and the database......Page 320
9.1.3 The story of the lost message......Page 321
9.2 Transaction basics......Page 322
9.2.1 About Spring’s transaction support......Page 323
9.2.2 Adding transactions......Page 324
9.2.3 Testing transactions......Page 326
9.3 The Transactional Client EIP......Page 329
9.3.1 Using local transactions......Page 330
9.3.2 Using global transactions......Page 331
9.4.1 Configuring transactions......Page 334
9.4.2 Using transactions with multiple routes......Page 336
9.4.3 Returning a custom response when a transaction fails......Page 339
9.5.1 Introducing UnitOfWork......Page 342
9.5.2 Using Synchronization callbacks......Page 343
9.5.3 Using onCompletion......Page 345
9.6 Summary and best practices......Page 346
Concurrency and scalability......Page 348
10.1 Introducing concurrency......Page 349
10.1.2 Using concurrency......Page 351
10.2.1 Understanding thread pools in Java......Page 356
10.2.2 Camel thread pool profiles......Page 359
10.2.3 Creating custom thread pools......Page 361
10.2.4 Using ExecutorServiceStrategy......Page 362
10.3 Using concurrency with EIPs......Page 363
10.3.1 Using concurrency with the Threads EIP......Page 364
10.3.2 Using concurrency with the Multicast EIP......Page 365
10.3.3 Using concurrency with the Wire Tap EIP......Page 367
10.4 Synchronicity and threading......Page 368
10.4.1 Asynchronous caller using one thread......Page 369
10.4.2 Synchronous caller using one thread......Page 370
10.4.3 Asynchronous caller using multiple threads......Page 372
10.4.4 Synchronous caller using multiple threads......Page 373
10.4.5 Returning an early reply to a caller......Page 375
10.5.1 The concurrency client API in Java......Page 377
10.5.2 The concurrency client API in Camel......Page 380
10.6.1 Hitting the scalability limit......Page 383
10.6.2 Scalability in Camel......Page 385
10.6.3 Components supporting asynchronous processing......Page 386
10.6.4 Asynchronous API......Page 387
10.6.5 Writing a custom asynchronous component......Page 389
10.7 Summary and best practices......Page 391
Developing Camel projects......Page 392
11.1.1 Using Camel Maven archetypes......Page 393
11.1.2 Camel Maven dependencies......Page 397
11.2.1 Using the Maven Eclipse plugin......Page 399
11.2.2 Using the m2eclipse plugin......Page 401
11.3.1 Setting up a new Camel component......Page 404
11.3.2 Diving into the implementation......Page 406
11.4.1 Creating an InterceptStrategy......Page 410
11.5.1 The Scala DSL......Page 413
11.5.3 Mixing Java and Scala......Page 415
11.6 Summary and best practices......Page 417
Management and monitoring......Page 418
12.1.1 Checking health at the network level......Page 419
12.1.3 Checking health at the application level......Page 421
12.2 Using JMX with Camel......Page 422
12.2.1 Using JConsole to manage Camel......Page 423
12.2.2 Using JConsole to remotely manage Camel......Page 424
12.3.1 Using log files......Page 426
12.3.3 Using custom logging......Page 427
12.3.4 Using Tracer......Page 431
12.3.5 Using notifications......Page 435
12.4.1 Managing Camel application lifecycles......Page 438
12.4.2 Managing custom Camel components......Page 439
12.5 Summary and best practices......Page 442
Running and deploying Camel......Page 443
13.1.1 How Camel starts......Page 444
13.1.2 Camel startup options......Page 446
13.1.3 Ordering routes......Page 449
13.1.4 Disabling autostartup......Page 451
13.2 Starting and stopping routes at runtime......Page 452
13.2.1 Using CamelContext to start and stop routes at runtime......Page 453
13.2.2 Using RoutePolicy to start and stop routes at runtime......Page 455
13.3 Shutting down Camel......Page 457
13.3.1 Graceful shutdown......Page 458
13.4.1 Embedded in a Java application......Page 461
13.4.2 Embedded in a web application......Page 463
13.4.3 Embedded in JBoss Application Server......Page 469
13.5 Camel and OSGi......Page 470
13.5.1 Setting up Maven to generate an OSGi bundle......Page 471
13.5.2 Installing and running Apache Karaf......Page 472
13.5.3 Deploying the example......Page 473
13.6 Summary and best practices......Page 474
Bean routing and remoting......Page 476
14.1.1 Inventory update at Rider Auto Parts......Page 477
14.1.2 Receiving messages with @Consume......Page 478
14.1.3 Sending messages with @Produce......Page 481
14.1.4 When to use beans for routing......Page 483
14.2 Hiding middleware......Page 484
14.2.1 Introducing the starter kit......Page 486
14.2.2 Using Spring remoting and Camel proxies......Page 489
14.3 Summary and best practices......Page 493
A.1 Introducing Simple......Page 494
A.3 Built-in variables......Page 495
A.4 Built-in functions......Page 496
A.5 Built-in file variables......Page 498
A.6 Built-in operators......Page 499
A.7 The OGNL feature......Page 501
A.8 Using Simple from custom Java code......Page 502
A.9 Summary......Page 503
B.1.1 Standard expressions......Page 504
B.1.2 Using custom expressions......Page 505
B.2 Predicates......Page 506
B.2.2 Using custom predicates......Page 507
B.2.3 Using compound predicates......Page 508
B.3 Summary......Page 509
C.1 The ProducerTemplate......Page 510
C.1.1 Using the ProducerTemplate......Page 511
C.2 The ConsumerTemplate......Page 513
C.2.1 Using the ConsumerTemplate......Page 514
C.3 Summary......Page 515
D.2 FuseSource......Page 516
D.3 Camel Tooling......Page 517
D.4 Camel-extra project......Page 518
D.7 Other resources......Page 519
appendix E: Akka and Camel......Page 520
E.2 Getting started with Akka actors......Page 521
E.3.1 One-way messaging......Page 523
E.3.2 Request-response messaging......Page 524
E.4 Producing messages to Camel endpoints......Page 525
E.5.1 Programmatic customization......Page 527
E.5.2 Declarative customization......Page 528
E.6 The Actor component......Page 529
E.7 A routing example......Page 530
E.8 Summary......Page 532
A......Page 534
B......Page 535
C......Page 536
E......Page 540
I......Page 542
L......Page 543
O......Page 544
R......Page 545
S......Page 546
T......Page 547
X......Page 549
Back cover......Page 550