www.devoxx.com
Apache ActiveMQ and
Apache ServiceMix

    Bruce Snyder
    Senior Software Engineer
    SpringSource




                www.devoxx.com
Agenda
Message-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                               www.devoxx.com
What is
Message-Oriented
  Middleware?
 4     www.devoxx.com
What is MOM?

     "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)




 5                            www.devoxx.com
What is MOM?

 "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)




 6                             www.devoxx.com
Message-Oriented Middleware




 7          www.devoxx.com
Enterprise Carrier Pigeon ;-)




  8            www.devoxx.com
What is the
    Java Message
      Service?
9        www.devoxx.com
What is JMS?


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




 10                            www.devoxx.com
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




   11                         www.devoxx.com
Apache Software
  Foundation

12    www.devoxx.com
Installing ActiveMQ
 Download it
 Unzip it
 Run it



 It’s really that simple!




  13                        www.devoxx.com
Configuring ActiveMQ




  (conf/activemq.xml)
 14                     www.devoxx.com
Configuring ActiveMQ
 Not only XML configuration
  Embedding via Java is also very common
        Lightweight
        Damn easy to use




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

 ...

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

   15                                  www.devoxx.com
ActiveMQ Uses URIs
 <protocol>://<host>:<port>?<transport-options>


  vm://embedded?broker.persistent=false


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


  stomp://localhost:61613


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




 16                         www.devoxx.com
Wire Formats
 OpenWire
 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
 XMPP
 The Jabber XML protocol
 REST
 HTTP POST and GET
 AMQP
 Not yet fully supported
  17                           www.devoxx.com
Two Types of Transports
 Client-to-broker communications




 Broker-to-broker communications




  18                     www.devoxx.com
Transport Connectors
 Client-to-broker connections
 Similar to JDBC connections to a database
 Protocols are supported:
 TCP
 UDP
 NIO
 SSL
 HTTP/S
 VM
 XMPP




  19                          www.devoxx.com
Network Connectors
 Broker-to-broker connections
 A cluster of ActiveMQ instances
       Known as a network of brokers

 Protocols supported:
 Static
 Failover
 Multicast
 Zeroconf
 Peer
 Fanout
 Discovery


  20                                   www.devoxx.com
Message Persistence
 AMQ Store
 JDBC
 Journaled JDBC




  21              www.devoxx.com
AMQ Message Store
 Transactional 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                            www.devoxx.com
Non-Journaled JDBC
 Transactional message storage solution
 Reliable but not fast
 JDBC connection overhead is prohibitively slow




  23                          www.devoxx.com
Journaled JDBC
 Transactional message storage solution
 Reliable and faster than non-journaled
 Two-piece store
 Journal - A high-performance, transactional journal
 Database - A relational database of your choice
 Default persistence in ActiveMQ 4.x
 Default database in ActiveMQ 4.x was Apache Derby




  24                           www.devoxx.com
Related - Message Cursors
 Messages are no longer stored in memory
 Previous 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                          www.devoxx.com
Master/Slave Configurations
 Pure master/slave
 Shared filesystem master/slave
 JDBC master/slave




  26                     www.devoxx.com
Pure Master/Slave
 Shared nothing, fully replicated topology
  Does 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                          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                                     www.devoxx.com
Shared Filesystem Master/Slave
 Utilizes 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                       www.devoxx.com
JDBC Master/Slave
 Recommended 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                       www.devoxx.com
M/S Client Connectivity
 Clients should use failover transport for auto-
 reconnect:


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




  31                     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                              www.devoxx.com
Broker Security
 Authentication
  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 Plugins
  http://ttmsolutions.com/
  33                             www.devoxx.com
Networks of Brokers
 Many 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                          www.devoxx.com
Topology Example




 35         www.devoxx.com
Topology Example




 36         www.devoxx.com
Topology Example




 37         www.devoxx.com
Topology Example




 38         www.devoxx.com
Topology Example




 39         www.devoxx.com
Using ActiveMQ
    Three options:




1                    2
                         EJB                 3

                     Message-Driven
                         Beans                      JMS
          DIY                                    Message-Driven
                                                    POJOs



     40                     www.devoxx.com
Do It Yourself (DIY)
 Advantages
 Do whatever you want - it’s a green field!


 Disadvantages
 Manual creation of MessageProducers and MessageConsumers
 Manual concurrency
 Manual thread management
 Manual transaction management
 Manual resource management
       ConnectionFactory, Connections, Destinations




  41                                   www.devoxx.com
EJB: Message-Driven Beans
      Advantages
      Automatic Transaction management
      Automatic Concurrency
      Automatic resource management
       ConnectionFactory, Connections, Destinations


      Disadvantages
      Requires EJB container and therefore a JEE server
       Exception: Apache OpenEJB (http://openejb.apache.org/ )
      Increased overhead



 42                                 www.devoxx.com
Spring JMS
 Advantages
 No EJB container required (no JEE container)
 Simplified resource management
       ConnectionFactory, Connections, Destinations
 Simplified concurrency management
 Simplified transaction management


 Disadvantages
 Are there any? ;-)




  43                                   www.devoxx.com
The Spring JmsTemplate
 browse()                                                   Synchronous
  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                                   www.devoxx.com
Sending Messages
 Using convertAndSend()                                                Synchronous




       JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate");

       jmsTemplate.convertAndSend("Hello World!");




  45                                     www.devoxx.com
Sending Messages
 Using send() with a MessageCreator                                    Synchronous
 Provides access to Session for more complex message creation



       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!");
          }
        });




  46                                      www.devoxx.com
Access the Session
 Using execute() the SessionCallback                                      Synchronous
 Provides access to the Session for flexibility



       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);
         }
       });




  47                                     www.devoxx.com
Access the Session or Message Producer
 Using execute() with the ProducerCallback                                Synchronous
  Provides access to the Session and the MessageProducer for more
  complex scenarios


       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;
         }
       });




  48                                      www.devoxx.com
Receiving Messages
 Using receiveAndConvert()                                                 Synchronous




       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!");
          }
        });




  49                                     www.devoxx.com
Spring Message-Driven POJOs
 SimpleMessageListenerContainer                      Asynchronous
 Very basic
 No dynamic resizing offered
 DefaultMessageListenerContainer
 Most common
 Allows for dynamic resizing
 Can participate in transactions
 ServerSessionMessageListenerContainer
 Most powerful
 Less commonly used
 Relies upon the ServerSessionPool support from the JMS provider


  50                               www.devoxx.com
Spring Message-Driven POJOs
 Three types                                                     Asynchronous
 javax.jms.MessageListener interface
       Standard JEE interface
       Threading is up to you
 SessionAwareMessageListener interface
       Spring-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                                            www.devoxx.com
Receiving Messages
                                                                  Asynchronous

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



    (Spring 2.5+)
   52                                    www.devoxx.com
Message Receiver
 No JMS dependencies                                                      Asynchronous


 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);
 
        }
 }




     53                                     www.devoxx.com
Consumer Options
 Message prefetch
 Exclusive consumer
 Consumer priority
 Message groups
 Redelivery policies
 Retroactive consumer
 Selectors
 Some slow consumer strategies




  54                   www.devoxx.com
Message Prefetch
 Used for slow consumer situations
 Prevents flooding the consumer
 FIFO buffer on the consumer side




  55                       www.devoxx.com
Prefetch Limit

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




   56                                    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                         www.devoxx.com
Exclusive Consumer

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

   58                                        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                         www.devoxx.com
Consumer Priority

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

   60                                        www.devoxx.com
Message Groups
 Uses the JMSXGroupID property to define a group
 One consumer receives all messages in the group
 Allows one consumer to handle related messages




  61                         www.devoxx.com
Message Groups
 Set programmatically:

       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);
         }
       });




  62                                     www.devoxx.com
Redelivery Policy
 Messages 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                            www.devoxx.com
Redelivery Policy
 Clients can override the redelivery policy programatically:

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




  64                                    www.devoxx.com
Redelivery Policy
 Also configurable via activemq.xml:

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




  65                                  www.devoxx.com
Retroactive Consumer
 Message replay at start of a subscription
  At the start of every subscription, send any old messages
  that the consumer may have missed
 Configurable via recovery policies




  66                       www.devoxx.com
Retroactive Consumer
 FixedSizedSubscriptionRecoveryPolicy
  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
 QueryBasedSubscriptionRecoveryPolicy
  Perform a user specific query to load any message they may have missed (uses JMS
  selectors)
 TimedSubscriptionRecoveryPolicy
  Keep a timed buffer (in ms) of messages around in memory and use that to recover new
  subscriptions


  67                                     www.devoxx.com
Redelivery Policy
 Give each queue it’s own DLQ:

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


 * Configured in conf/activemq.xml


  68                                 www.devoxx.com
Message Selectors
 Used to attach a filter to a subscription

 JMS selectors
  Defined 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                                        www.devoxx.com
Other Handy Features
 Destination Policies
 Virtual Destinations
 Total Ordering of Messages
 Mirrored Queues

 * Configured in conf/activemq.xml




  70                         www.devoxx.com
Wildcards on Destination Policies
       ...
       <destinationPolicy>
         <policyMap>
           <policyEntries>
             <policyEntry topic="Price.Stock.>"
                 memoryLimit="128mb">
           </policyEntries>
         </policyMap>
       </destinationPolicy>
       ...


 • Price.>
 • Price.Stock.>
                                       > - Everything recursively
                                       * - Everything at that level
 • Price.Stock.NASDAQ.*
 • Price.Stock.*.IBM


  71                            www.devoxx.com
Virtual Destinations




 72            www.devoxx.com
Total Ordering
 A guaranteed order of messages for each consumer




  73                     www.devoxx.com
Mirrored Queues




 74         www.devoxx.com
What is Apache Camel?




                              =>


http://activemq.apache.org/                    http://eaipatterns.com/

    75                        www.devoxx.com
Message Routing With Camel
 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");
 
            }
 
          };
 }




     76                                   www.devoxx.com
Message Routing Made Easy
 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>




  77                               www.devoxx.com
Content Based Router (Java)



      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");
         }
      };


 78                                        www.devoxx.com
Content Based Router (XML)
 <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>


  79                                            www.devoxx.com
Coming Soon: ActiveMQ in Action




 80          www.devoxx.com
Let’s Take a Break

Up Next ...

Apache ServiceMix



                www.devoxx.com
Integration is Messy!




 82           www.devoxx.com
83   www.devoxx.com
What is an
      ESB?

84      www.devoxx.com
What is an ESB?

      "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)




 85                            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                             www.devoxx.com
What is an ESB?

      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)




 87                              www.devoxx.com
Do I need an ESB?
    Article at IBM developerWorks
      Written 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-




      88                                    www.devoxx.com
Use a Planning Process
          ESB Planning Process




 89             www.devoxx.com
What is
      JBI?

90     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                              www.devoxx.com
Java Business Integration




 92           www.devoxx.com
Java Business Integration




 93           www.devoxx.com
JBI Normalized Message




 94         www.devoxx.com
JBI Packaging




 95             www.devoxx.com
Apache ServiceMix




       http://servicemix.apache.org/

 96              www.devoxx.com
Apache ServiceMix Architecture




 97          www.devoxx.com
ServiceMix Features
 Supports many protocols
 File, FTP, HTTP/S, JMS, SMTP, SOAP, TCP, XMPP
 Supports many engines
 Apache 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 Integration
 Geronimo, JBoss, Jetty, Tomcat, Weblogic, Websphere


  98                       www.devoxx.com
Apache Software
  Foundation

99    www.devoxx.com
Message Routing




 100        www.devoxx.com
Message Routing




 101        www.devoxx.com
Hello World
                 with ServiceMix




www.devoxx.com
Configuration
 Involves configuring existing components using XML




 103                     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                                   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                                    www.devoxx.com
The Logger: Java Code
    public 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                        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                           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                                 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                                    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                                 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                                  www.devoxx.com
Hello World
                 with ServiceMix




www.devoxx.com
JBI Packaging




 113            www.devoxx.com
Distributed ServiceMix Containers




 114          www.devoxx.com
Eclipse IDE Tooling For ServiceMix
 Eclipse SOA Tooling Platform (STP) Project
 http://eclipse.org/stp

 Spagic
 http://spagic.com/

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




 115                                   www.devoxx.com
Eclipse Tooling




         Eclipse SOA Tools Platform (STP) Project

 116              www.devoxx.com
Apache
      ServiceMix
          4.0
117       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                         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                          www.devoxx.com
ServiceMix 4 Architecture




 120          www.devoxx.com
ServiceMix 4 Architecture




 121          www.devoxx.com
Do You Have Information Overload Yet?




 122            www.devoxx.com
Thank You!

Questions?




             www.devoxx.com

Apache ActiveMQ and Apache ServiceMix

  • 1.
  • 2.
    Apache ActiveMQ and ApacheServiceMix Bruce Snyder Senior Software Engineer SpringSource www.devoxx.com
  • 3.
    Agenda Message-based integration ApacheActiveMQ 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 www.devoxx.com
  • 4.
    What is Message-Oriented Middleware? 4 www.devoxx.com
  • 5.
    What is MOM? "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) 5 www.devoxx.com
  • 6.
    What is MOM? "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) 6 www.devoxx.com
  • 7.
  • 8.
    Enterprise Carrier Pigeon;-) 8 www.devoxx.com
  • 9.
    What is the Java Message Service? 9 www.devoxx.com
  • 10.
    What is JMS? "JMS provides a common way for Java programs to create, send, receive and read an enterprise messaging systemʼs messages.” (JMS spec) 10 www.devoxx.com
  • 11.
    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 11 www.devoxx.com
  • 12.
    Apache Software Foundation 12 www.devoxx.com
  • 13.
    Installing ActiveMQ Downloadit Unzip it Run it It’s really that simple! 13 www.devoxx.com
  • 14.
    Configuring ActiveMQ (conf/activemq.xml) 14 www.devoxx.com
  • 15.
    Configuring ActiveMQ Notonly XML configuration Embedding via Java is also very common Lightweight Damn easy to use BrokerService broker = new BrokerService(); broker.setPersistence(false); TransportConnector connector = broker.addConnector("tcp://localhost:61616"); broker.start(); ... connector.stop(); broker.stop(); 15 www.devoxx.com
  • 16.
    ActiveMQ Uses URIs <protocol>://<host>:<port>?<transport-options> vm://embedded?broker.persistent=false tcp://localhost:61616?jms.useAsyncSend=true stomp://localhost:61613 failover:(tcp://host1:61616,tcp://host2:61616)? initialReconnectDelay=100 16 www.devoxx.com
  • 17.
    Wire Formats OpenWire 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 XMPP The Jabber XML protocol REST HTTP POST and GET AMQP Not yet fully supported 17 www.devoxx.com
  • 18.
    Two Types ofTransports Client-to-broker communications Broker-to-broker communications 18 www.devoxx.com
  • 19.
    Transport Connectors Client-to-brokerconnections Similar to JDBC connections to a database Protocols are supported: TCP UDP NIO SSL HTTP/S VM XMPP 19 www.devoxx.com
  • 20.
    Network Connectors Broker-to-brokerconnections A cluster of ActiveMQ instances Known as a network of brokers Protocols supported: Static Failover Multicast Zeroconf Peer Fanout Discovery 20 www.devoxx.com
  • 21.
    Message Persistence AMQStore JDBC Journaled JDBC 21 www.devoxx.com
  • 22.
    AMQ Message Store Transactional 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 www.devoxx.com
  • 23.
    Non-Journaled JDBC Transactionalmessage storage solution Reliable but not fast JDBC connection overhead is prohibitively slow 23 www.devoxx.com
  • 24.
    Journaled JDBC Transactionalmessage storage solution Reliable and faster than non-journaled Two-piece store Journal - A high-performance, transactional journal Database - A relational database of your choice Default persistence in ActiveMQ 4.x Default database in ActiveMQ 4.x was Apache Derby 24 www.devoxx.com
  • 25.
    Related - MessageCursors Messages are no longer stored in memory Previous 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 www.devoxx.com
  • 26.
    Master/Slave Configurations Puremaster/slave Shared filesystem master/slave JDBC master/slave 26 www.devoxx.com
  • 27.
    Pure Master/Slave Sharednothing, fully replicated topology Does 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 www.devoxx.com
  • 28.
    Pure Master/Slave Ifthe 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 www.devoxx.com
  • 29.
    Shared Filesystem Master/Slave Utilizes 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 www.devoxx.com
  • 30.
    JDBC Master/Slave Recommendedwhen 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 www.devoxx.com
  • 31.
    M/S Client Connectivity Clients should use failover transport for auto- reconnect: failover:(tcp://broker1:61616, tcp://broker2:61616, tcp://broker3:61616)? initialReconnectDelay=100 31 www.devoxx.com
  • 32.
    Tips for HAand Fault Tolerance RAIDed disks A Storage Area Network Clustered relational databases Clustered JDBC via C-JDBC http://sequoia.continuent.org/ 32 www.devoxx.com
  • 33.
    Broker Security Authentication 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 Plugins http://ttmsolutions.com/ 33 www.devoxx.com
  • 34.
    Networks of Brokers Many 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 www.devoxx.com
  • 35.
    Topology Example 35 www.devoxx.com
  • 36.
    Topology Example 36 www.devoxx.com
  • 37.
    Topology Example 37 www.devoxx.com
  • 38.
    Topology Example 38 www.devoxx.com
  • 39.
    Topology Example 39 www.devoxx.com
  • 40.
    Using ActiveMQ Three options: 1 2 EJB 3 Message-Driven Beans JMS DIY Message-Driven POJOs 40 www.devoxx.com
  • 41.
    Do It Yourself(DIY) Advantages Do whatever you want - it’s a green field! Disadvantages Manual creation of MessageProducers and MessageConsumers Manual concurrency Manual thread management Manual transaction management Manual resource management ConnectionFactory, Connections, Destinations 41 www.devoxx.com
  • 42.
    EJB: Message-Driven Beans Advantages Automatic Transaction management Automatic Concurrency Automatic resource management ConnectionFactory, Connections, Destinations Disadvantages Requires EJB container and therefore a JEE server Exception: Apache OpenEJB (http://openejb.apache.org/ ) Increased overhead 42 www.devoxx.com
  • 43.
    Spring JMS Advantages No EJB container required (no JEE container) Simplified resource management ConnectionFactory, Connections, Destinations Simplified concurrency management Simplified transaction management Disadvantages Are there any? ;-) 43 www.devoxx.com
  • 44.
    The Spring JmsTemplate browse() Synchronous 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 www.devoxx.com
  • 45.
    Sending Messages UsingconvertAndSend() Synchronous JmsTemplate jmsTemplate = (JmsTemplate) context.getBean("jmsTemplate"); jmsTemplate.convertAndSend("Hello World!"); 45 www.devoxx.com
  • 46.
    Sending Messages Usingsend() with a MessageCreator Synchronous Provides access to Session for more complex message creation 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!"); } }); 46 www.devoxx.com
  • 47.
    Access the Session Using execute() the SessionCallback Synchronous Provides access to the Session for flexibility 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); } }); 47 www.devoxx.com
  • 48.
    Access the Sessionor Message Producer Using execute() with the ProducerCallback Synchronous Provides access to the Session and the MessageProducer for more complex scenarios 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; } }); 48 www.devoxx.com
  • 49.
    Receiving Messages UsingreceiveAndConvert() Synchronous 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!"); } }); 49 www.devoxx.com
  • 50.
    Spring Message-Driven POJOs SimpleMessageListenerContainer Asynchronous Very basic No dynamic resizing offered DefaultMessageListenerContainer Most common Allows for dynamic resizing Can participate in transactions ServerSessionMessageListenerContainer Most powerful Less commonly used Relies upon the ServerSessionPool support from the JMS provider 50 www.devoxx.com
  • 51.
    Spring Message-Driven POJOs Three types Asynchronous javax.jms.MessageListener interface Standard JEE interface Threading is up to you SessionAwareMessageListener interface Spring-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 www.devoxx.com
  • 52.
    Receiving Messages Asynchronous <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> (Spring 2.5+) 52 www.devoxx.com
  • 53.
    Message Receiver NoJMS dependencies Asynchronous 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); } } 53 www.devoxx.com
  • 54.
    Consumer Options Messageprefetch Exclusive consumer Consumer priority Message groups Redelivery policies Retroactive consumer Selectors Some slow consumer strategies 54 www.devoxx.com
  • 55.
    Message Prefetch Usedfor slow consumer situations Prevents flooding the consumer FIFO buffer on the consumer side 55 www.devoxx.com
  • 56.
    Prefetch Limit <beanid="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> 56 www.devoxx.com
  • 57.
    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 www.devoxx.com
  • 58.
    Exclusive Consumer <beanid="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> 58 www.devoxx.com
  • 59.
    Consumer Priority Gives a consumer preference for message delivery Allows for the weighting of consumers to optimize network traversal for message delivery 59 www.devoxx.com
  • 60.
    Consumer Priority <beanid="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> 60 www.devoxx.com
  • 61.
    Message Groups Usesthe JMSXGroupID property to define a group One consumer receives all messages in the group Allows one consumer to handle related messages 61 www.devoxx.com
  • 62.
    Message Groups Setprogrammatically: 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); } }); 62 www.devoxx.com
  • 63.
    Redelivery Policy Messagesare 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 www.devoxx.com
  • 64.
    Redelivery Policy Clientscan override the redelivery policy programatically: ... RedeliveryPolicy policy = connectionFactory.getRedeliveryPolicy(); policy.setInitialRedeliveryDelay(500); policy.setBackOffMultiplier((short) 2); policy.setUseExponentialBackOff(true); policy.setMaximumRedeliveries(4); ... 64 www.devoxx.com
  • 65.
    Redelivery Policy Alsoconfigurable via activemq.xml: <destinationPolicy> <policyMap> <policyEntries> <policyEntry topic=">"> <!-- 1 minutes worth --> <subscriptionRecoveryPolicy> <timedSubscriptionRecoveryPolicy recoverDuration="60000" /> </subscriptionRecoveryPolicy> </policyEntry> </policyEntries> </policyMap> </destinationPolicy> 65 www.devoxx.com
  • 66.
    Retroactive Consumer Messagereplay at start of a subscription At the start of every subscription, send any old messages that the consumer may have missed Configurable via recovery policies 66 www.devoxx.com
  • 67.
    Retroactive Consumer FixedSizedSubscriptionRecoveryPolicy 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 QueryBasedSubscriptionRecoveryPolicy Perform a user specific query to load any message they may have missed (uses JMS selectors) TimedSubscriptionRecoveryPolicy Keep a timed buffer (in ms) of messages around in memory and use that to recover new subscriptions 67 www.devoxx.com
  • 68.
    Redelivery Policy Giveeach queue it’s own DLQ: <destinationPolicy> <policyMap> <policyEntries> <policyEntry topic=">"> <deadLetterStrategy> <individualDeadLetterStrategy queuePrefix="DLQ." useQueueForQueueMessages="true" /> </deadLetterStrategy> </policyEntry> </policyEntries> </policyMap> </destinationPolicy> * Configured in conf/activemq.xml 68 www.devoxx.com
  • 69.
    Message Selectors Usedto attach a filter to a subscription JMS selectors Defined 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 www.devoxx.com
  • 70.
    Other Handy Features Destination Policies Virtual Destinations Total Ordering of Messages Mirrored Queues * Configured in conf/activemq.xml 70 www.devoxx.com
  • 71.
    Wildcards on DestinationPolicies ... <destinationPolicy> <policyMap> <policyEntries> <policyEntry topic="Price.Stock.>" memoryLimit="128mb"> </policyEntries> </policyMap> </destinationPolicy> ... • Price.> • Price.Stock.> > - Everything recursively * - Everything at that level • Price.Stock.NASDAQ.* • Price.Stock.*.IBM 71 www.devoxx.com
  • 72.
    Virtual Destinations 72 www.devoxx.com
  • 73.
    Total Ordering Aguaranteed order of messages for each consumer 73 www.devoxx.com
  • 74.
    Mirrored Queues 74 www.devoxx.com
  • 75.
    What is ApacheCamel? => http://activemq.apache.org/ http://eaipatterns.com/ 75 www.devoxx.com
  • 76.
    Message Routing WithCamel 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"); } }; } 76 www.devoxx.com
  • 77.
    Message Routing MadeEasy 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> 77 www.devoxx.com
  • 78.
    Content Based Router(Java) 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"); } }; 78 www.devoxx.com
  • 79.
    Content Based Router(XML) <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> 79 www.devoxx.com
  • 80.
    Coming Soon: ActiveMQin Action 80 www.devoxx.com
  • 81.
    Let’s Take aBreak Up Next ... Apache ServiceMix www.devoxx.com
  • 82.
    Integration is Messy! 82 www.devoxx.com
  • 83.
    83 www.devoxx.com
  • 84.
    What is an ESB? 84 www.devoxx.com
  • 85.
    What is anESB? "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) 85 www.devoxx.com
  • 86.
    What is anESB? 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 www.devoxx.com
  • 87.
    What is anESB? 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) 87 www.devoxx.com
  • 88.
    Do I needan ESB? Article at IBM developerWorks Written 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- 88 www.devoxx.com
  • 89.
    Use a PlanningProcess ESB Planning Process 89 www.devoxx.com
  • 90.
    What is JBI? 90 www.devoxx.com
  • 91.
    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 www.devoxx.com
  • 92.
    Java Business Integration 92 www.devoxx.com
  • 93.
    Java Business Integration 93 www.devoxx.com
  • 94.
    JBI Normalized Message 94 www.devoxx.com
  • 95.
    JBI Packaging 95 www.devoxx.com
  • 96.
    Apache ServiceMix http://servicemix.apache.org/ 96 www.devoxx.com
  • 97.
  • 98.
    ServiceMix Features Supportsmany protocols File, FTP, HTTP/S, JMS, SMTP, SOAP, TCP, XMPP Supports many engines Apache 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 Integration Geronimo, JBoss, Jetty, Tomcat, Weblogic, Websphere 98 www.devoxx.com
  • 99.
    Apache Software Foundation 99 www.devoxx.com
  • 100.
    Message Routing 100 www.devoxx.com
  • 101.
    Message Routing 101 www.devoxx.com
  • 102.
    Hello World with ServiceMix www.devoxx.com
  • 103.
    Configuration Involves configuringexisting components using XML 103 www.devoxx.com
  • 104.
    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 www.devoxx.com
  • 105.
    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 www.devoxx.com
  • 106.
    The Logger: JavaCode public 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 www.devoxx.com
  • 107.
    The Logger: CamelConfig <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 www.devoxx.com
  • 108.
    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 www.devoxx.com
  • 109.
    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 www.devoxx.com
  • 110.
    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 www.devoxx.com
  • 111.
    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 www.devoxx.com
  • 112.
    Hello World with ServiceMix www.devoxx.com
  • 113.
    JBI Packaging 113 www.devoxx.com
  • 114.
  • 115.
    Eclipse IDE ToolingFor ServiceMix Eclipse SOA Tooling Platform (STP) Project http://eclipse.org/stp Spagic http://spagic.com/ Sopera http://sopera.de/en/products/sopera-servicemixtools/ 115 www.devoxx.com
  • 116.
    Eclipse Tooling Eclipse SOA Tools Platform (STP) Project 116 www.devoxx.com
  • 117.
    Apache ServiceMix 4.0 117 www.devoxx.com
  • 118.
    Lessons Learned FromJBI 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 www.devoxx.com
  • 119.
    ServiceMix 4.0 BuildingBlocks 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 www.devoxx.com
  • 120.
    ServiceMix 4 Architecture 120 www.devoxx.com
  • 121.
    ServiceMix 4 Architecture 121 www.devoxx.com
  • 122.
    Do You HaveInformation Overload Yet? 122 www.devoxx.com
  • 123.
    Thank You! Questions? www.devoxx.com