15
Exploring Apache Camel Vitalii Tymchyshyn [email protected] @tivv00

Exploring Apache Camel

  • Upload
    -

  • View
    1.137

  • Download
    0

Embed Size (px)

DESCRIPTION

Introduction to Apache Camn

Citation preview

Page 1: Exploring Apache Camel

Exploring Apache Camel

Vitalii [email protected]

@tivv00

Page 2: Exploring Apache Camel

Typical IoC application

Container Filters

MVC framework Views

Controller Controller Controller

Service Service Service

DAO DAO DAO

EXT

Page 3: Exploring Apache Camel

Typical IoC application

This is your call stack: everyone's busy processing the request!

Page 4: Exploring Apache Camel

Camel applicationConsumers(e.g. Jetty)

Camel

Filters Controllers Services

EXTDAOs Views

Page 5: Exploring Apache Camel

Camel application

Everyone's doing it's workConveyor is provided by Camel

Page 6: Exploring Apache Camel

Some camel ext connectors● HTTP (Jetty, Client v3, Client v4, GAE, Servlet)

● MQ (AMQP, ActiveMQ, ZeroMQ, MQTT, SQS)

● DB (JPA, DynamoDB, SimpleDB, CouchDB, Hazelcast, Hbase, iBatis, JDBC, MongDB, Zookeeper, Hibernate)

● BLOB (File, HDFS, FTP, SCP, S3)

● RPC (CXF, RMI, Avro, SSH, JGroups)

● ...

Page 7: Exploring Apache Camel

EIP patterns

1 2 3?

C

A B

D

!

E

Page 8: Exploring Apache Camel

Main camel primitivesContext

Component

Endpoint

Producer / Consumer

RouteBuilder

RouteDefinition

Route

Exchange

Page 9: Exploring Apache Camel

Camel RegistryCamel supports components lookup with plugable mechanism named Registry.

Next registry types are supported out of box:● Simple — simple map-based ● JNDI — looks up objects in JNDI● ApplicationContext — looks up objects in Spring

This means that Camel easily intergrates with Spring for complex components assembling and configuration

Page 10: Exploring Apache Camel

Camel DSLsCamel routes can be expressed in next DSLs:

✔ Java / Groovy /Scala / Kotlin (WiP)✔ Spring XML / Blueprint XML✔ Annotations

Java examplefrom("test-jms:queue:test.queue")

.to("file://test");

Spring example<route> <from uri="test-jms:queue:test.queue"/> <to uri="file://test"/></route>

Page 11: Exploring Apache Camel

Adding own codeYou can write your own component / endpoint / consumer / producer

➔ Good when you are developing reusable component, need advanced features or making a consumer

Or simply call a POJO➔ When you simply need some logic

public class MyService { Answer process(Request arg) { ... }}

<bean id=”myService” class=”MyService”/><route> <from uri="servlet:callMyService"/> <unmarshall><jaxb .../></unmarshall> <to uri="bean:myService"/> <marshall><jaxb .../></marshall></route>

Page 12: Exploring Apache Camel

Reusing routes➔ You can use

“direct” component to call routes from another routes or your code.

➔ Use direct-vm to call routes from another context

<route> <from uri="direct:save"/> <to uri="file://test"/></route>

<route> ... <to uri="direct:save"/> ...</route>

@EndpointInject(uri = "direct:save") ProducerTemplate saveRoute;...SaveRoute.sendBody(“testBody”);

Page 13: Exploring Apache Camel

Handling exceptionsYou can define exception handling directly in camel routes. It can:

● Use different strategies based on exception class

● Perform automatic retries (redeliveries)● Call “exceptional” route● Define “continue” or “stop route” handlers

Page 14: Exploring Apache Camel

Monitoring your routesCamel automatically gathers statistics on your routes and provides it with JMX.

Statistics is:● Enabled by default● Provides detailed statistics up to single endpoint

level● Has timings and success/failure counters● Can be retrieved as a single XML file for the route

or the whole context

Page 15: Exploring Apache Camel

Questions? Suggestions?