real world #microservices with apache camel, fabric8, and openshift
TRANSCRIPT
Real-world #microservices
with Apache Camel and
Fabric8
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!
• Microservices
• Heavy lifting with Apache Camel
• Managing microservices with Fuse,
Fabric8 v1
• OpenShift, Fabric8 v2
• Beer (lots?)
Agenda
Why do we care?
Micro what?
• Services, reuse, composition
• Loose coupling!
• Contracts
• Incremental change
• “Business Agility”
SOA!
SOA made smaller… micro even…
So what are microservices?
A term that helps describe distributed systems
that organically evolve into scalable, loosely
coupled, modular sets of services that work
together to deliver business value
with acceptable tradeoffs.
So what are microservices?
• If my services are isolated at the
process level, I’m doing
#microservices
• If I use REST/Thrift/ProtoBuf
instead of SOAP, I’m doing
#microservices
• If I use JSON, I’m doing
#microservices
• If I use no-container / SpringBoot
/ Dropwizard / embedded Jetty,
I’m doing #microservices
I’m doing microservices if…
• Agile methodology
• SOA principles
• Domain Driven Design
• Hexagonal Architectures
• Pipes and Filters
• Actor Model
• REST
• SEDA
Microservices emerged as a result…
• Modularity!
• Flexible technology options
• “Smart endpoints” “dumb pipes”
• Evolving design
• Independently scalable
• Automation, DevOps philosophy
• Decentralized, choreographed interactions
• Testable
• Design for failure
Microservices…
Isolation: logical or physical?
• 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 ahead…
Apache Camel for
microservices?
Real developers ride Camels!
2
2
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>
Camel - JBoss Developer Studio
• 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
• Content Based Router
• Dynamic Router
• Routing Slip
• Recipient List
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 breaker
Image from http://martinfowler.com/bliki/CircuitBreaker.html
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”);
}
}
More Information● Camel in Action
● Apache Camel Developer’s Cookbook
● Community website
○ http://camel.apache.org/
JBoss Fuse (Red Hat
product)
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
Managing microservice
deployments
• Simplifies deployments
• Provides centralized configuration
• Versioning
• Visualization of your middleware
• Service discovery
• Smart load balancing
• Failover
• Provides cluster capabilities, coordination
http://fabric8.io
• Implemented with Zookeeper and git
• Intended to be used with a dynamic
JVM/Apache Karaf
• Profiles store configuration, metadata, end-
state deployments
• Networking, JVM isolation, orchestration,
auto-scaling, health checks, cloud
deployments: all up to you
Fabric8 V1.x
• Registry• Where configs are stored, everything centrally
managed
• Profiles• Description of end-state deployment of a server
• Agent
• Listens on the server that can respond to registry
changes/profile updates
Fabric8 V1.x
Quick Demo V1
• Implemented with Docker and Kubernetes
• Use any JVM (or any technology)
• Docker images, encourage static, well-
defined, well-tested deployments
• Provides networking, JVM isolation,
orchestration, auto-scaling, health checks,
cloud deployments
• Still in community! Proving this out!
Fabric8 V2
Docker / Linux Containers
How different than VMs?
Kubernetes
• Pods
• Services
• Replication Controllers
Kubernetes
Red Hat’s PaaS: OpenShift
Public
PaaS
Service
On-premise
or Private
PaaS
Software
Open
Source
PaaS
Project
Scale IT Like a Factory with PaaS
Quick Demo V2
Demo and Questions