Integrating Microservices with Apache Camel
Transcript of Integrating Microservices with Apache Camel
2
Who?Christian Posta
Principal Middleware Specialist/Architect
Blog: http://christianposta.com/blog
Twitter: @christianposta
Email: [email protected]
• Committer on Apache Camel, ActiveMQ, Fabric8, PMC on ActiveMQ
• Author: Essential Camel Components DZone Refcard
• Frequent blogger and speaker about open-source technology!
• Domain modeling
• Object Oriented design
• Functional decomposiiton
• Language specific modularity,
decomposition, fault-tolerance (eg, Erlang)
• Shared libraries?
Decomposition techniques
• Agile methodology
• Doman Driven Design
• REST
• Hexagonal Architectures
• Pipes and Filters
• Actor Model
• SEDA
Microservices emerged as a result…
A new term! Yay!
A concept that helps describe distributed
systems that organically evolve into scalable,
loosely coupled, independently managed sets
of services that work together to deliver
business value with acceptable tradeoffs.
So what are microservices?
Don’t get too caught up in the buzzword bingo;
Microservices is a good concept, but it’s not
itself a panacea.
So what are Microservices?
• Flexible technology choices
• “Smart endpoints” “dumb pipes”
• Independently scalable
• Decentralized, choreographed interactions
• Testable
• Automation, DevOps philosophy
• Design for failure
• Evolving design
Microservice characteristics
• No silver bullet; distributed systems are
*hard*
• Dependency hell, custom shared libraries
• Fragmented and inconsistent management
• Team communication challenges
• Health checking, monitoring, liveness
• Over architecting, performance concerns,
things spiraling out of control fast
Challenges with Microservices!
1
7
Apache CamelApache Camel is an open-source,
light-weight, integration library.
Use Camel to integrate disparate systems
that speak different protocols and data formats
Apache Camel
Enterprise Integration Patterns
http://camel.apache.org/eip
Features
● Enterprise Integration Patterns (EIPs)
● Domain Specific Language to write “flows” or “routes”
● Large collection of adapters/components for legacy
systems, B2B, and SaaS
● Strong Unit test/Integration test framework
● Expression languages
● Data Formats
● Tooling with JBoss Developer Studio
Java DSLpublic class OrderProcessorRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from(“activemq:orders”)
.choice()
.when(header(“customer-rating”).isEqualTo(“gold”))
.to(“ibmmq:topic:specialCustomer”)
.otherwise()
.to(“ftp://user@host/orders/regularCustomers”)
.end()
.log(“received new order ${body.orderId}”)
.to(“ibatis:storeOrder?statementType=Insert”);
}
}
Spring XML DSL<route id=“processOrders”>
<from uri=“activemq:orders”/>
<choice>
<when>
<simple>${header.customer-rating} == ‘gold’</simple>
<to uri=“wmq:topic:specialCustomer”>
</when>
<otherwise>
<to uri=“ftp://user@host/orders/regularCustomers” />
</otherwise>
</choice>
<log message=“received new order ${body.orderId}”/>
<to uri=“ibatis:storeOrder?statementType=Insert”/>
</route>
• Dynamic routing options
• REST DSL
• Backpressure mechanisms
• Loadbalancing algorithms / Circuit Breaker
pattern
Heavy Lifting: Camel for Microservices
• “Smart endpoints, dumb pipes”
• Endpoint does one thing well
• Metadata used for further routing
• Really “dynamic” with rules engine (eg,
Drools/BRMS)
Dynamic Routing
• Expressive way to define REST endpoints
• POST, REST, PUT
• Auto binding to POJOs
• Plugs into Swagger for interface
definition/documentation
• Uses configurable HTTP engine• camel-netty-http
• camel-jetty
• camel-reslet
• camel-sevlet (deploy into other containers)
• camel-spark-rest
REST DSL (2.14)
REST DSLpublic class OrderProcessorRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
rest().post(“/order/socks”)
.description(“New Order for pair of socks”)
.consumes(“application/json”)
.route()
.to(“activemq:topic:newOrder”)
.log(“received new order ${body.orderId}”)
.to(“ibatis:storeOrder?statementType=Insert”);
}
}
• Backpressure is a way for a service to flow
control callers
• Detecting when can be difficult
• Need to bound processing queues in a
SEDA
• Take advantage of built in TCP flow control
for socket/http requests
Backpressure with Camel
• Throttle EIP• http://camel.apache.org/throttler.html
• Blocking SEDA Queue
• from(“seda:name?size=100&blockWhenFull=true)
• Configure jetty/netty to use blocking acceptor
queues
• https://wiki.eclipse.org/Jetty/Howto/High_Load
• Using Exception handling/retry and DLQ
logic when getting flow controlled• http://camel.apache.org/error-handling-in-camel.html
Backpressure with Camel
• Useful to keep from overloading a system
(use in conjunction with backpressure if you
can)
• Smart loadbalancing• Sticky
• Random
• Failover
• Circuit breaker
Loadbalance/Circuit breaker
Circuit breakerpublic class OrderProcessorRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from(“direct:someinterface”)
.loadbalance()
.circuitBreaker(3, 20000L, MyException.class)
.to(“ibatis:storeOrder?statementType=Insert”);
}
}
Apache Camel
More Information● Camel in Action
● Apache Camel Developer’s Cookbook
● Community website
○ http://camel.apache.org/
RED HAT JBOSS FUSE
Development and tooling
Develop, test, debug, refine,
deploy
JBoss Developer Studio
Web services frameworkWeb services standards, SOAP,
XML/HTTP, RESTful HTTP
Integration frameworkTransformation, mediation, enterprise
integration patterns
Management and
monitoring
System and web services metrics,
automated discovery, container
status, automatic updates
JBoss Operations Network
+
JBoss Fabric Management
Console
(hawtio)
Apache CXF Apache Camel
Reliable MessagingJMS/STOMP/NMS/MQTT, publishing-subscribe/point-2-point, store and forward
Apache ActiveMQ
ContainerLife cycle management, resource management, dynamic deployment,
security and provisioning
Apache Karaf + Fuse Fabric
RED HAT ENTERPRISE LINUXWindows, UNIX, and other Linux
• Simplifies deployments
• Provides centralized configuration
• Provides cluster capabilities, coordination
• Service discovery
• Smart load balancing
• Failover
• Versioning
• Visualize your middleware with HawtIO
http://fabric8.io