con1715 eisele eisele riding a camel throught the jeehara

80
Riding a Camel through the JEEHara Markus Eisele, @myfear Developer Advocate [email protected] October, 2015

Upload: sbabuind

Post on 10-Jul-2016

229 views

Category:

Documents


6 download

DESCRIPTION

OOW2015 Eisele Riding a Camel Throught the Jeehara

TRANSCRIPT

Page 1: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Riding a Camel through the JEEHara

Markus Eisele, @myfearDeveloper [email protected], 2015

Page 2: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara
Page 3: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara
Page 4: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara
Page 5: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Gregor Hohpe (@ghohpe) and Bobby Wolf

Page 6: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

camel.apache.org/eip

Page 7: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Why Camel?

Page 8: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Service Bus Messaging Data Virt

Legacy App Legacy App Data

App

Mic

ros

erv

ice

Mic

ros

erv

ice

Mic

ros

erv

ice

Mic

ros

erv

ice

Mic

ros

erv

ice

Legacy AppLegacy App Legacy App

App

App

App

App

Page 9: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

1

1) More Services Produced- Legacy Apps- Newly Designed- Infrastructure Level

- Different Protocols- Custom and Standard Apps

Page 10: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

2

2) More Services Consumed- More Apps- Decentralized- Chained Services

- Lightweight Connectors- Standardized Protocols- EAI Problems move to

apps- Monitoring- Distributed Responsibility

Page 11: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Easy & Lightweight

Applications are done by Developers. So, pleeeeaaasssseee ...

Page 12: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Therefore Camel!

Page 13: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• Open source integration library

• Simple lightweight, use in any JVM or application

server

• Can be programmed and not sketched

• Connects to anything

• 100s of components connecting to databases, file

systems, messaging systems, big data, SaaS

providers, social media, ...

• Tooling

Page 14: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

How? Show me!

Page 15: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara
Page 16: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

package org.javaee.why;

import javax.annotation.Resource;import javax.ejb.MessageDriven;import javax.jms.Connection;import javax.jms.ConnectionFactory;import javax.jms.DeliveryMode;import javax.jms.JMSException;import javax.jms.Message;import javax.jms.MessageListener;import javax.jms.MessageProducer;import javax.jms.Queue;import javax.jms.Session;import javax.jms.TextMessage;

@MessageDrivenpublic class SortOrdersBean implements MessageListener {

@Resourceprivate ConnectionFactory connectionFactory;

@Resource(name = “WidgetQueue")private Queue widget;

@Resource(name = “TheRestQueue")private Queue theRest

public void onMessage(Message message) {try {

final TextMessage order = (TextMessage) message;final String type = order.getText();

if (“widget".equals(type)) {

respond("widget", message);} else {

respond("rest", message);}

} catch (JMSException e) {throw new IllegalStateException(e);

}}

private void respond(String type, Message message) throws JMSException {

Connection connection = null;Session session = null;

try {connection = connectionFactory.createConnection();connection.start();

// Create a Sessionsession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

// Create a MessageProducer from the Session to the Topic or QueueMessageProducer producer = session.createProducer(widget);producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

// Create a messageTextMessage message = session.createTextMessage(text);

// Tell the producer to send the messageproducer.send(message);

} finally {// Clean upif (session != null) session.close();if (connection != null) connection.close();

}}

}

• It’s Java EE 6 (7 is simpler)

• Where’s my routing logic?

• Introspecting messages

• .

• .

• .

• Sigh.

Page 17: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

from newOrderchoice

Page 18: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

from newOrderchoice

when isWidget to widget

Page 19: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

from newOrderchoice

when isWidget to widgetotherwise to theRest

Page 20: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

from (newOrder)choice

when (isWidget) to (widget)otherwise to (theRest)

Page 21: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

from (newOrder).choice()

.when(isWidget).to(widget)

.otherwise().to(theRest);

Page 22: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

from (newOrder).choice()

.when(isWidget).to(widget)

.otherwise().to(theRest);.end();

Endpoint newOrder = endpoint(“jms:incomming");Predicate isWidget = xpath("/order/product/type = 'widget'");Endpoint widget = endpoint(“jms:widget");Endpoint gadget = endpoint(“jms:theRest");

Page 23: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

import org.apache.camel.Endpoint;import org.apache.camel.Predicate;import org.apache.camel.builder.RouteBuilder;

public class MyRoute extends RouteBuilder {

public void configure() throws Exception {Endpoint newOrder = endpoint(“jms:incomming");Predicate isWidget = xpath("/order/product/type = 'widget'");Endpoint widget = endpoint(“jms:widget");Endpoint gadget = endpoint(“jms:theRest");

from(newOrder).choice().when(isWidget).to(widget).otherwise().to(theRest)

.end();}

}

Ja

va

co

de

Page 24: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Coool!

Page 25: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

import org.apache.camel.builder.RouteBuilder;

public class MyRoute extends RouteBuilder {

public void configure() throws Exception {

from("jms:incomming").choice().when(xpath("/order/product/type = 'widget'"))

.to("jms:widget").otherwise().to("jms:theRest")

.end();}

}

Ja

va

DS

L

Page 26: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

<route><from uri="jms:newOrder" /><choice>

<when><xpath>/order/product/type='widget'</xpath><to uri="jms:widget"/>

</when><otherwise>

<to uri="jms:theRest"/></otherwise>

</choice></route>

XM

L D

SL

Page 27: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Gro

ov

y D

SL

import org.apache.camel.builder.RouteBuilder;

public class MyRoute extends RouteBuilder {

public void configure() throws Exception {

from("jms:incomming").choice()

.when({ it.in.header('zipcode') ==~ /\d+/ }).to("jms:widget")

.otherwise().to("jms:theRest")}

}

Page 28: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Sc

ala

DS

L class FilterRoute {def createMyFilterRoute = new RouteBuilder {

from("direct:start").filter(_.in("gold") == "true").to("mock:gold")

}}

Page 29: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

import org.apache.camel.builder.RouteBuilder;

public class MyRoute extends RouteBuilder {

public void configure() throws Exception {

from("file:inbox/orders?delete=true").choice().when(xpath("/order/product/type = 'widget'"))

.to("jms:widget").otherwise().to("jms:theRest")

.end();}

}

Co

nfi

gu

re E

nd

po

ints

as

UR

Is

Page 30: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara
Page 31: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://camel.apache.org/component.html

150+ Components

Page 32: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://fineartamerica.com/featured/apache-camel-components-poster-gliesian-llc.html

Page 33: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

rest("/user").description("User rest service").consumes("application/json").produces("application/json")

.get("/{id}").description("Find user by id").outType(User.class).to("bean:userService?method=getUser(${header.id})")

.put().description("Updates or create a user").type(User.class).to("bean:userService?method=updateUser")

.get("/findAll").description("Find all users").outTypeList(User.class).to("bean:userService?method=listUsers");

Page 34: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://blog.eisele.net/2014/12/camel-on-java-ee-7-rest-services-swagger-api-doc.html

Page 35: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://camel.apache.org/data-format.html

19 Data Formats

Page 36: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

// JSON Data Format// lets turn Object messages into json (Xstream) then send to MQSeriesfrom("activemq:My.Queue").marshal().json().to("mqseries:Another.Queue");

/** Alternative Librariesmarshal().json(JsonLibrary.Jackson)marshal().json(JsonLibrary.Gson).

**/

// Camel RSS Data Format// only entries with Camel in the title will get through the filterfrom("rss:file:src/test/data/rss20.xml?splitEntries=true&consumer.delay=100")

.marshal()

.rss()

.filter().xpath("//item/title[contains(.,'Camel')]").to("mock:result");

Page 37: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://camel.apache.org/languages.html

15 Expression Languages

Page 38: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

// lets route if a line item is over $100from("queue:foo").filter(groovy("request.lineItems.any { i -> i.value > 100 }")).to("queue:bar")

// route exchanges from admin users to a special queue.from("direct:start")

.choice().when().javaScript("request.headers.get(&#39;user&#39;) == &#39;admin&#39;").to("seda:adminQueue")

.otherwise().to("seda:regularQueue");

Page 39: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Wow!

Page 40: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• Integration Framework• Enterprise Integration Patterns (EIP)• Routing DSLs• Endpoint as URIs• Just Java or XML code (or even more)• No Container Dependency• A hell lot of ready made components• Expressions and Date-Formats

Page 41: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

FTW!

Page 42: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Deploying Camel

Page 43: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

camel-core.jar = 2.8 MB!

Page 44: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• Deployment Options• Standalone• Spring• Java EE• OSGi

Page 45: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• Containers• Apache ActiveMQ• Apache Karaf• Apache ServiceMix• Apache Tomcat• Fabric8• JBoss AS / WildFly• JBoss Fuse• JBoss Fuse Service Works• Jetty• WebLogic• Glassfish • WebSphere

Page 46: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Camel & Java EE

Page 47: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

@Singleton@Startuppublic class Bootstrap {

@InjectCdiCamelContext context;

@PostConstructpublic void init() {

// create routes

// Start Camel Contextcontext.start();

}

@PreDestroypublic void shutdown() {

// Graceful Shutdown Camel Contextcontext.stop();

}

http://blog.eisele.net/2014/08/bootstrapping-apache-camel-in-java-ee7.html

#1

Ca

me

l CD

I

Page 48: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• Not all components are working as expected• Deployment gets really large• Easy to run into classloading issues

Ke

ep

in M

ind

!

Page 49: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

#2

Cu

sto

m M

od

ule

https://sourcevirtues.wordpress.com/2013/11/25/add-apache-camel-and-spring-as-jboss-module-in-wildfly/

• Create a Spring Module• Create a Camel Module

Page 50: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• The module dependencies have to be correct.• Need to reference modules from

jboss-deployment-structure.xml• No pre-build list / no support

Ke

ep

in M

ind

!

Page 51: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

#3

Ca

me

l Su

bsy

ste

m

https://github.com/wildfly-extras/wildfly-camel

• Simply apply the wildfly-camel-patch to a compatible wildfly version

• wildflyext/wildfly-camel docker distribution

Page 52: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

@Startup@ApplicationScoped@ContextName("jms-camel-context")public class JmsRouteBuilder extends RouteBuilder {

@Resource(mappedName = "java:jboss/DefaultJMSConnectionFactory")private ConnectionFactory connectionFactory;

@Overridepublic void configure() throws Exception {JmsComponent component = new JmsComponent();component.setConnectionFactory(connectionFactory);

getContext().addComponent("jms", component);

from("timer://sendJMSMessage?fixedRate=true&period=10000").transform(constant("<?xml version='1.0><message><greeting>hello

world</greeting></message>")).to("jms:queue:WildFlyCamelQueue").log("JMS Message sent");

}}

Page 53: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• Not all components contained so far• Still under development• Growing component base

http://wildflyext.gitbooks.io/wildfly-camel/content/

Ke

ep

in M

ind

!

Page 54: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Camel and JavaEE

are awesome!

Page 55: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara
Page 56: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

What users are telling us

Page 57: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• Camel rocks in development• very easy to get started and create small projects

• can I have more tooling?• need help scaling to 1000s of services and • need help moving integration solutions through

Deployment pipeline

Page 58: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Something is missing

Page 59: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara
Page 60: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://fabric8.io/

Page 61: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• an open source integration platform

• designed to make it easy to deploy, manage and scale

integration solutions

• helps move integration solutions from

dev -> test -> prod

Page 62: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

What does it do?

Page 63: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• provision, configure and manage services

• perform incremental and rolling upgrades of

changes

• discovery and load balancing of services

• elastic scaling of services

Page 64: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

How does that look like?

Page 65: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• 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

Page 66: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

• 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

Page 67: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

CamelApp

Configuration

Fabric8

Instance 1 App SpecConf

Instance 2 App SpecConf

Instance 3 App SpecConf

Instance 4 App SpecConf

Instance … App SpecConf

Instance n App SpecConf

Profile

DeveloperPC

Networking

Orchestration

Auto-Scaling

Health Checks

Console

Maven

Versioning

Deployment

Distribution

Page 68: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

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

• Will support OpenShift v3

Fabric8 V2

Page 69: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

V1 vs. V2• Profiles

• Runtime Registry

• Configuration

Repository

• Tooling

• Profiles

• Docker

• Kubernetes

• PODs

• Labels

• Services

• Apps

• App Zips

• Builds

Page 70: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://camel.apache.org/download.html

http://www.jboss.org/products/devstudio/overview/

Do

wn

loa

d a

nd

inst

all

http://fabric8.io/v2/

Page 71: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara
Page 72: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

Wanna know more ?

Page 73: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://camel.apache.org/examples

Page 74: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara
Page 75: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://camel.apache.org/mailing-lists.html

http://stackoverflow.com/questions/tagged/apache-camel

http://camel.apache.org/irc-room.html

http://fabric8.io/v2/

Page 76: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

What else ?

Page 77: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://camel.apache.org/commercial-camel-offerings.html

+

Page 78: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://bit.ly/virtualJBUG

@vJBUG

Page 79: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara

http://developers.redhat.com/promotions/distributed-javaee-architecture

Page 80: CON1715 Eisele Eisele Riding a Camel Throught the Jeehara