apache activemq and apache servicemix

123
www.devoxx.com

Upload: bruce-snyder

Post on 07-Nov-2014

15.386 views

Category:

Technology


6 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Page 2: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Apache ActiveMQ and Apache ServiceMix

Bruce SnyderSenior Software EngineerSpringSource

Page 3: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

AgendaMessage-based integration

Apache ActiveMQ Installing ActiveMQ

Configuring ActiveMQ

Using ActiveMQ with Spring JMS

Some ActiveMQ Features

Message routing with Apache Camel

Apache ServiceMix Enterprise Service Bus

Java Business Integration

Apache ServiceMix ESB

More message routing with Apache Camel

3

Page 4: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

What is Message-Oriented

Middleware?4

Page 5: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

"Software that connects separate systems in a network by carrying and distributing messages between them. MOM infrastructure is typically built around a queuing system that stores messages pending delivery, and keeps track of whether and when each message has been delivered.” (LooselyCoupled.com)

What is MOM?

5

Page 6: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

"A client/server infrastructure that increases the interoperability, portability, and flexibility of an application by allowing it to be distributed over multiple heterogeneous platforms. It reduces the complexity of developing applications that span multiple operating systems and network protocols by insulating the application developer from the details of the various operating system and network interfaces.”

(Wikipedia.com)

What is MOM?

6

Page 7: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Message-Oriented Middleware

7

Page 8: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Enterprise Carrier Pigeon ;-)

8

Page 9: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

What is theJava Message

Service?9

Page 10: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

"JMS provides a common way for Java programs to create, send, receive and read an enterprise messaging systemʼs messages.” (JMS spec)

What is JMS?

10

Page 11: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com11

What is ActiveMQ?• Open source

• Message-oriented middleware

• Apache project

–http://activemq.apache.org/

• Apache licensed

• JMS 1.1 compliant

• Goal:

–To achieve standards-based, message-oriented application integration across many languages and platforms

Page 12: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Apache Software Foundation

12

Page 13: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Installing ActiveMQDownload it

Unzip it

Run it

It’s really that simple!

13

Page 14: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Configuring ActiveMQ

(conf/activemq.xml)14

Page 15: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Configuring ActiveMQNot only XML configuration Embedding via Java is also very common

Lightweight

Damn easy to use

15

BrokerService broker = new BrokerService();broker.setPersistence(false);TransportConnector connector = broker.addConnector("tcp://localhost:61616");broker.start();

...

connector.stop();broker.stop();

Page 16: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

ActiveMQ Uses URIs

vm://embedded?broker.persistent=false

tcp://localhost:61616?jms.useAsyncSend=true

stomp://localhost:61613

failover:(tcp://host1:61616,tcp://host2:61616)?initialReconnectDelay=100

16

<protocol>://<host>:<port>?<transport-options>

Page 17: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Wire FormatsOpenWire The default in ActiveMQ; a binary protocol

Clients for C++, Java and .NET

STOMP Simple Text Oriented Messaging Protocol; a text based protocol

Clients for C, Javascript, Perl, PHP, Python, Ruby and more

XMPPThe Jabber XML protocol

RESTHTTP POST and GET

AMQP Not yet fully supported 17

Page 18: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Two Types of TransportsClient-to-broker communications

Broker-to-broker communications

18

Page 19: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Transport ConnectorsClient-to-broker connectionsSimilar to JDBC connections to a database

Protocols are supported: TCP

UDP

NIO

SSL

HTTP/S

VM

XMPP

19

Page 20: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Network ConnectorsBroker-to-broker connections A cluster of ActiveMQ instances

Known as a network of brokers

Protocols supported: Static

Failover

Multicast

Zeroconf

Peer

Fanout

Discovery

20

Page 21: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Message PersistenceAMQ Store

JDBC

Journaled JDBC

21

Page 22: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

AMQ Message StoreTransactional message storage solution

Fast and reliable

Composed of two parts: Data Store - holds messages in a transactional journal

Reference store - stores message locations for fast retrieval

The default message store in ActiveMQ 5

22

Page 23: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Non-Journaled JDBCTransactional message storage solution

Reliable but not fast JDBC connection overhead is prohibitively slow

23

Page 24: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Journaled JDBCTransactional message storage solution

Reliable and faster than non-journaled

Two-piece storeJournal - A high-performance, transactional journal

Database - A relational database of your choice

Default persistence in ActiveMQ 4.xDefault database in ActiveMQ 4.x was Apache Derby

24

Page 25: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Related - Message CursorsMessages are no longer stored in memoryPrevious to 5.1, message references were stored in memory

Messages are paged in from storage when space is available in memory

Lots of configurability

25

Page 26: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Master/Slave ConfigurationsPure master/slave

Shared filesystem master/slave

JDBC master/slave

26

Page 27: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Pure Master/Slave Shared nothing, fully replicated topologyDoes not depend on shared filesystem or database

A Slave broker consumes all commands from the master broker (messages, acks, tx states)

Slave does not start any networking or transport connectors

Master broker will only respond to client when a message exchange has been successfully passed to the slave broker

27

Page 28: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Pure Master/Slave If the master fails, the slave optionally has two modes of operation: Start up all it’s network and transport connectors

All clients connected to failed Master resume on Slave

Close down completely Slave is simply used to duplicate state from Master

28

Page 29: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Shared Filesystem Master/SlaveUtilizes a directory on a shared filesystem

No restriction on number of brokers

Simple configuration (point to the data dir)

One master selected at random

29

Page 30: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

JDBC Master/SlaveRecommended when using a shared database

No restriction on the number of brokers

Simple configuration

Clustered database negates single point of failure

One master selected at random

30

Page 31: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

M/S Client ConnectivityClients should use failover transport for auto-reconnect:

31

failover:(tcp://broker1:61616, \tcp://broker2:61616, \tcp://broker3:61616)? \initialReconnectDelay=100

Page 32: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Tips for HA and Fault Tolerance RAIDed disks

A Storage Area Network

Clustered relational databases

Clustered JDBC via C-JDBC http://sequoia.continuent.org/

32

Page 33: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Broker SecurityAuthentication I.e., are you allowed to connect to ActiveMQ?

File based implementation

JAAS based implementation

Authorization I.e., do you have permission to use that ActiveMQ resource?

Destination level

Message level via custom plugin

Additional Security Pluginshttp://ttmsolutions.com/ 33

Page 34: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Networks of BrokersMany distributed ActiveMQ brokers working together

Provides large scalability by clustering brokers

ActiveMQ store-and-forward allows messages to traverse brokers in the network Demand-based forwarding

Some people call this distributed queues

Many possible configurations or topologies are supported

34

Page 35: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Topology Example

35

Page 36: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Topology Example

36

Page 37: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Topology Example

37

Page 38: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Topology Example

38

Page 39: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Topology Example

39

Page 40: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

EJBMessage-Driven

Beans

Using ActiveMQThree options:

40

JMSMessage-Driven

POJOs

1 2 3

DIY

Page 41: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Do It Yourself (DIY)AdvantagesDo whatever you want - it’s a green field!

DisadvantagesManual creation of MessageProducers and MessageConsumers

Manual concurrency

Manual thread management

Manual transaction management

Manual resource management ConnectionFactory, Connections, Destinations

41

Page 42: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

EJB: Message-Driven Beans

AdvantagesAutomatic Transaction management

Automatic Concurrency

Automatic resource management ConnectionFactory, Connections, Destinations

DisadvantagesRequires EJB container and therefore a JEE server

Exception: Apache OpenEJB (http://openejb.apache.org/ )

Increased overhead

42

Page 43: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Spring JMSAdvantagesNo EJB container required (no JEE container)

Simplified resource management ConnectionFactory, Connections, Destinations

Simplified concurrency management

Simplified transaction management

DisadvantagesAre there any? ;-)

43

Page 44: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

The Spring JmsTemplatebrowse()

Browse messages in a queue

convertAndSend()

Send messages synchronously

Convert a Java object to a JMS message

execute()

Provides access to callbacks for more complex scenarios

receive() and receiveAndConvert()

Receive messages synchronously

receiveSelected() and receiveSelectedAndConvert()

Receive filtered messages synchronously

send()

Send a message synchronously using a MessageCreator

44

Synchronous

Page 45: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Sending Messages Using convertAndSend()

45

JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate"); jmsTemplate.convertAndSend("Hello World!");

Synchronous

Page 46: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Sending Messages Using send() with a MessageCreator Provides access to Session for more complex message creation

46

Destination destination = (Destination) context.getBean("queue");JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate"); jmsTemplate.send(destination, new MessageCreator() { public Message createMessage(Session session) throws JMSException { return session.createTextMessage("Hello World!"); } });

Synchronous

Page 47: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Access the SessionUsing execute() the SessionCallbackProvides access to the Session for flexibility

47

JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate"); jmsTemplate.execute(new SessionCallback() { public Object doInJms(Session session) throws JMSException { Queue queue = session.createQueue("MY.TEST.QUEUE"); MessageProducer producer = session.createProducer(queue); Message message = session.createTextMessage("Hello World!"); producer.send(message); }});

Synchronous

Page 48: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Access the Session or Message Producer

Using execute() with the ProducerCallback Provides access to the Session and the MessageProducer for more complex scenarios

48

JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate"); jmsTemplate.execute(new ProducerCallback() { public Object doInJms(Session session, MessageProducer producer) throws JMSException { Message message = session.createTextMessage("Hello World!"); producer.send(destination, message); } return null; }});

Synchronous

Page 49: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Receiving Messages Using receiveAndConvert()

49

Destination destination = (Destination) context.getBean("queue");JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate"); jmsTemplate.receiveAndConvert(destination, new MessageCreator() { public Message createMessage(Session session) throws JMSException { return session.createTextMessage("Hello World!"); } });

Synchronous

Page 50: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Spring Message-Driven POJOsSimpleMessageListenerContainerVery basic

No dynamic resizing offered

DefaultMessageListenerContainerMost common

Allows for dynamic resizing

Can participate in transactions

ServerSessionMessageListenerContainerMost powerful

Less commonly used

Relies upon the ServerSessionPool support from the JMS provider

50

AsynchronousAsynchronous

Page 51: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Spring Message-Driven POJOsThree typesjavax.jms.MessageListener interface

Standard JEE interface

Threading is up to you

SessionAwareMessageListener interfaceSpring-specific interface

Provides access to the Session object

Useful for request-response messaging

Client must handle exceptions

MessageListenerAdapter interface Spring-specific interface

Allows for type-specific message handling

No JMS dependencies whatsoever

51

Asynchronous

Page 52: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Receiving Messages

(Spring 2.5+)52

<bean id="amqConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616" /></bean>

<bean id="messageReceiver" class="com.mycompany.MessageReceiver" />

<jms:listener-container connection-factory="connectionFactory" concurrency="3"> <jms:listener id="myMessageListener" ref="messageReceiver" destination="MY.TEST.QUEUE" method="processMessage" /></jms:listener-container>

Asynchronous

Page 53: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Message ReceiverNo JMS dependencies

53

public class MessageReceiver {

public void processMessage(String message) { System.out.println("Received a String message: " + message); } public void processMessage(Map message) { System.out.println("Received a Map message: " + message); }}

Asynchronous

Page 54: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Consumer OptionsMessage prefetch

Exclusive consumer

Consumer priority

Message groups

Redelivery policies

Retroactive consumer

Selectors

Some slow consumer strategies

54

Page 55: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Message PrefetchUsed for slow consumer situations Prevents flooding the consumer

FIFO buffer on the consumer side

55

Page 56: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Prefetch Limit

56

<bean id="amqConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616?consumer.prefetchSize=10" /></bean>

<bean id="messageReceiver" class="com.mycompany.jms.MessageReceiver" />

<jms:listener-container connection-factory="connectionFactory" concurrency="3"> <jms:listener id="myMessageListener" ref="messageReceiver" destination="MY.TEST.QUEUE" method="processMessage" /></jms:listener-container>

Page 57: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Exclusive Consumer

Anytime more than one consumer is consuming from a queue, message order is lost

Allows a single consumer to consume all messages on a queue to maintain message ordering

57

Page 58: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Exclusive Consumer

58

<bean id="amqConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616?jms.prefetchPolicy.queuePrefetch=1" /></bean>

<bean id="messageReceiver" class="com.mycompany.jms.MessageReceiver" />

<bean id="queue" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg value="TEST.FOO?consumer.exclusive=true" /> </bean>

<jms:listener-container connection-factory="connectionFactory" concurrency="3"> <jms:listener id="myMessageListener" ref="messageReceiver" destination="MY.TEST.QUEUE" method="processMessage" /></jms:listener-container>

Page 59: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Consumer Priority

Gives a consumer preference for message delivery

Allows for the weighting of consumers to optimize network traversal for message delivery

59

Page 60: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Consumer Priority

60

<bean id="amqConnectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory"> <property name="brokerURL" value="tcp://localhost:61616?jms.prefetchPolicy.queuePrefetch=1" /></bean>

<bean id="messageReceiver" class="com.mycompany.jms.MessageReceiver" />

<bean id="queue" class="org.apache.activemq.command.ActiveMQQueue"> <constructor-arg value="TEST.FOO?consumer.priority=10" /> </bean>

<jms:listener-container connection-factory="connectionFactory" concurrency="3"> <jms:listener id="myMessageListener" ref="messageReceiver" destination="MY.TEST.QUEUE" method="processMessage" /></jms:listener-container>

Page 61: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Message GroupsUses the JMSXGroupID property to define a group

One consumer receives all messages in the group

Allows one consumer to handle related messages

61

Page 62: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Message GroupsSet programmatically:

62

JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate"); jmsTemplate.execute(new SessionCallback() { public Object doInJms(Session session) throws JMSException { Queue queue = session.createQueue("MY.TEST.QUEUE"); MessageProducer producer = session.createProducer(queue); Message message = session.createBytesMessage(); message.writeObject(someObject); message. setStringProperty("JMSXGroupID", "COLLATERAL_TRADE_X"); producer.send(message); }});

Page 63: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Redelivery PolicyMessages are redelivered to a client only when:A transacted session is rolled back

A transacted session is closed before commit

A session is using CLIENT_ACKNOWLEDGE and Session.recover() is explicitly called

Clients can override the redelivery policy Dead Letter Strategy can also be configured in activemq.xml

63

Page 64: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Redelivery PolicyClients can override the redelivery policy programatically:

64

...RedeliveryPolicy policy = connectionFactory.getRedeliveryPolicy();policy.setInitialRedeliveryDelay(500);policy.setBackOffMultiplier((short) 2);policy.setUseExponentialBackOff(true);policy.setMaximumRedeliveries(4);...

Page 65: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Redelivery PolicyAlso configurable via activemq.xml:

65

<destinationPolicy> <policyMap> <policyEntries> <policyEntry topic=">"> <!-- 1 minutes worth --> <subscriptionRecoveryPolicy> <timedSubscriptionRecoveryPolicy recoverDuration="60000" /> </subscriptionRecoveryPolicy> </policyEntry> </policyEntries> </policyMap></destinationPolicy>

Page 66: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Retroactive ConsumerMessage replay at start of a subscriptionAt the start of every subscription, send any old messages that the consumer may have missed

Configurable via recovery policies

66

Page 67: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Retroactive ConsumerFixedSizedSubscriptionRecoveryPolicy

Keep a fixed amount of memory in RAM for message history which is evicted in time order

FixedCountSubscriptionRecoveryPolicy Keep a fixed count of last messages

LastImageSubscriptionRecoveryPolicy Keep only the last message

NoSubscriptionRecoveryPolicy Disables message recovery

QueryBasedSubscriptionRecoveryPolicyPerform a user specific query to load any message they may have missed (uses JMS selectors)

TimedSubscriptionRecoveryPolicyKeep a timed buffer (in ms) of messages around in memory and use that to recover new subscriptions

67

Page 68: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Redelivery PolicyGive each queue it’s own DLQ:

* Configured in conf/activemq.xml

68

<destinationPolicy> <policyMap> <policyEntries> <policyEntry topic=">"> <deadLetterStrategy> <individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true" /> </deadLetterStrategy> </policyEntry> </policyEntries> </policyMap></destinationPolicy>

Page 69: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Message SelectorsUsed to attach a filter to a subscription

JMS selectorsDefined using a subset SQL 92 syntax

Filters only message properties JMSType = ‘stock’ and trader = ‘bob’ and price < ‘105’

XPath selectors Defined using XPath queries

Filters message bodies that contain XML‘/message/cheese/text() = 'swiss'’

69

Page 70: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Other Handy Features Destination Policies

Virtual Destinations

Total Ordering of Messages

Mirrored Queues

* Configured in conf/activemq.xml

70

Page 71: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Wildcards on Destination Policies

• Price.>• Price.Stock.>• Price.Stock.NASDAQ.*• Price.Stock.*.IBM

71

...<destinationPolicy> <policyMap> <policyEntries> <policyEntry topic="Price.Stock.>" memoryLimit="128mb"> </policyEntries> </policyMap></destinationPolicy>...

> - Everything recursively* - Everything at that level

Page 72: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Virtual Destinations

72

Page 73: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Total Ordering A guaranteed order of messages for each consumer

73

Page 74: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Mirrored Queues

74

Page 75: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

What is Apache Camel?

http://activemq.apache.org/

75

=>

http://eaipatterns.com/

Page 76: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Message Routing With Camel

76

Java API for message routing

package com.mycompany.routes;

public class MyRoute extends RouteBuilder { public void configure() { from("activemq:TEST.QUEUE").

to("file:///opt/inbox/text.txt"). to("log:MyLog?showProperties=true");

} };}

Page 77: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Message Routing Made Easy

77

XML flavor as well

<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <package>com.mycompany</package> <route> <from uri="activemq:example.A" /> <to uri="file:///opt/inbox/text.txt" /> <to uri=”log:MyLog?showProperties=true” /> </route></camelContext>

Page 78: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Content Based Router (Java)

78

RouteBuilder simpleChoiceRoute = new RouteBuilder() { public void configure() { from("activemq:QUEUE.A").choice(). when(header("foo").isEqualTo("bar")). to("file:/opt/inbox"). when(header("foo").isEqualTo("cheese")). to("jbi:service:http://com/mycompany/MyService"). otherwise(). to("file:/opt/outbox-foo"); }};

Page 79: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Content Based Router (XML)

79

<camelContext id="simpleChoiceRoute"> <route> <from uri="activemq:QUEUE.A" /> <choice> <when> <predicate> <header name="foo" /> <isEqualTo value="bar" /> </predicate> <to uri="file:/opt/inbox" /> </when> <when> <predicate> <header name="foo" /> <isEqualTo value="cheese" /> </predicate> <to uri="jbi:service:http://com/mycompany/MyService" /> </when> <otherwise> <to uri="file:/opt/outbox-foo" /> </otherwise> </choice> </route></camelContext>

Page 80: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Coming Soon: ActiveMQ in Action

80

Page 81: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Let’s Take a Break

Up Next ...

Apache ServiceMix

Page 82: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Integration is Messy!

82

Page 83: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com83

Page 84: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

What is an ESB?

84

Page 85: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

"An Enterprise Service Bus (ESB) is a new architecture that exploits Web services, messaging middleware, intelligent routing, and transformation. ESBs act as a lightweight, ubiquitous integration backbone through which software services and application components flow.” (Gartner)

What is an ESB?

85

Page 86: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

What is an ESB?

An ESB acts as a shared messaging layer for connecting applications and other services throughout an enterprise computing infrastructure. It supplements its core asynchronous messaging backbone with intelligent transformation and routing to ensure messages are passed reliably. Services participate in the ESB using either web services messaging standards or JMS (LooselyCoupled.com)

86

Page 87: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

An ESB is an open standards, message-based, distributed, integration solution that provides routing, invocation, and mediation services to facilitate the interactions of disparate distributed information technology resources (applications, services, information, platforms) in a reliable manner. (Brenda Michelson, Elemental Links)

What is an ESB?

87

Page 88: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Do I need an ESB?

88

Article at IBM developerWorksWritten by Bobby Woolf

General idea Don’t adopt an ESB without planning out the services first

ESB-oriented architecture:

The wrong approach to adopting SOA

http://www.ibm.com/developerworks/webservices/library/ws-soa-esbarch/index.html?ca=drs-

Page 89: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Use a Planning Process

ESB Planning Process

89

Page 90: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

What isJBI?

90

Page 91: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

What is JBI?

JBI defines an architecture that allows the construction of integration systems from plug-in components, that interoperate through the method of mediated message exchange.

(JBI 1.0 Spec)

91

Page 92: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Java Business Integration

92

Page 93: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Java Business Integration

93

Page 94: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

JBI Normalized Message

94

Page 95: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

JBI Packaging

95

Page 96: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Apache ServiceMix

http://servicemix.apache.org/

96

Page 97: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Apache ServiceMix Architecture

97

Page 98: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

ServiceMix FeaturesSupports many protocolsFile, FTP, HTTP/S, JMS, SMTP, SOAP, TCP, XMPP

Supports many enginesApache Camel, Apache CXF, Apache ODE, Drools, OS Workflow, POJOs, Quartz, Scripting, Saxon XQuery and XSLT, WS-Notification

Supports Security JAAS, WS-Security

Web Container/App Server IntegrationGeronimo, JBoss, Jetty, Tomcat, Weblogic, Websphere

98

Page 99: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Apache Software Foundation

99

Page 100: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Message Routing

100

Page 101: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Message Routing

101

Page 102: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Hello World with ServiceMix

Page 103: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Configuration

103

Involves configuring existing components using XML

Page 104: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

The File Poller<beans xmlns:file='http://servicemix.apache.org/file/1.0' xmlns:test="urn:test">

<file:poller service="test:file" endpoint="endpoint" targetService="test:wiretapIn" file="/Users/bsnyder/smxdropbox">

</beans>

104

Page 105: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

The Wiretap<beans xmlns:eip="http://servicemix.apache.org/eip/1.0"

xmlns:test="urn:test" >

<eip:wire-tap service="test:wiretapIn" endpoint="endpoint"> <eip:target> <eip:exchange-target service="test:cbr" /> </eip:target> <eip:inListener> <eip:exchange-target service="test:logger" /> </eip:inListener> </eip:wire-tap>

</beans>

105

Page 106: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

The Logger: Java Codepublic class MyLogger extends RouteBuilder {

public void configure() { from("jbi:service:urn:test:logger"). process(new Processor() { public void process(Exchange exchange) { Message in = exchange.getIn(); in.setBody(in.getBody(String.class) + "<foo>xxxxxxxxxxxxxxxxxxxxxxxxxxxx</foo>"); } }) to("log:Devoxx-DEMO"); }}

106

Page 107: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

The Logger: Camel Config<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">

<camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring"> <package>com.mycompany</package> </camelContext></beans>

107

Page 108: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

The Content-Based Router<beans xmlns:eip="http://servicemix.apache.org/eip/1.0" xmlns:test="urn:test">

<eip:content-based-router service="test:cbr" endpoint="endpoint"> <eip:rules> <eip:routing-rule> <eip:predicate> <eip:xpath-predicate xpath="/message/cheese/text() = 'gouda'" /> </eip:predicate> <eip:target> <eip:exchange-target service="test:queue1" /> </eip:target> </eip:routing-rule>...

108

Page 109: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

The Content-Based Router... <eip:routing-rule> <eip:predicate> <eip:xpath-predicate xpath="/message/cheese/text() = 'swiss'" /> </eip:predicate> <eip:target> <eip:exchange-target service="test:queue2" /> </eip:target> </eip:routing-rule> <eip:routing-rule> <eip:target> <eip:exchange-target service="test:queue3" /> </eip:target> </eip:routing-rule> </eip:rules> </eip:content-based-router>

109

Page 110: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

The JMS Sender<beans xmlns:jms="http://servicemix.apache.org/jms/1.0" xmlns:test="urn:test” xmlns:amq="http://activemq.org/config/1.0">

<jms:endpoint service="test:queue1" endpoint="myProvider" role="provider" destinationStyle="queue" jmsProviderDestinationName="queue1" connectionFactory="#connectionFactory" />

<jms:endpoint service="test:queue2" endpoint="myProvider" role="provider" destinationStyle="queue" jmsProviderDestinationName="queue2" connectionFactory="#connectionFactory"/>

110

Page 111: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

The JMS Sender... <jms:endpoint service="test:queue3" endpoint="myProvider" role="provider" destinationStyle="queue" jmsProviderDestinationName="queue3" connectionFactory="#connectionFactory"/>

<amq:connectionFactory id="connectionFactory" brokerURL="tcp://localhost:61616" />

</beans>

111

Page 112: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Hello World with ServiceMix

Page 113: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

JBI Packaging

113

Page 114: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Distributed ServiceMix Containers

114

Page 115: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Eclipse SOA Tooling Platform (STP) Projecthttp://eclipse.org/stp

Spagic http://spagic.com/

Sopera http://sopera.de/en/products/sopera-servicemixtools/

Eclipse IDE Tooling For ServiceMix

115

Page 116: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Eclipse Tooling

Eclipse SOA Tools Platform (STP) Project

116

Page 117: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Apache ServiceMix

4.0

117

Page 118: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Lessons Learned From JBI 1.0✓ Normalized Exchange and Messages✓ Normalized Message Router✓ The only way to plug in third party components

๏ XML normalization can be problematic ๏ Packaging/classloaders not very flexible ๏ Creating components is not easy๏ Not always the best fit for a given API

118

Page 119: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

ServiceMix 4.0 Building Blocks

Runtime: OSGi (Apache Felix)JBI support still intact

NMR is an OSGi service

Message Broker: Apache ActiveMQ

Web Services: Apache CXF

Routing Engine: Apache Camel

119

Page 120: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

ServiceMix 4 Architecture

120

Page 121: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

ServiceMix 4 Architecture

121

Page 122: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Do You Have Information Overload Yet?

122

Page 123: Apache ActiveMQ and Apache ServiceMix

www.devoxx.com

Thank You!

Questions?