Introduc6on to Ac6veMQ Apollo 




Bosanac Dejan
May 2011 




                                                                                                                                      A Progress So3ware Company 
       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.     FuseSource Confiden6al      A Progress So3ware Company 
1 
About me  

  Bosanac Dejan 
  Senior So3ware Engineer at FUSESource ‐ hNp://fusesource.com  
  Apache Ac6veMQ commiNer and PMC member 
  Co‐author of Ac6veMQ in Ac6on 




                                                                                                                  A Progress So3ware Company 
 2    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
What we are going to cover? 




  Why Apollo? 
  HawtDispatch 
  Connec6vity 
      •  Stomp 1.1, MQTT, JMS, ... 
  LevelDB Store 
  Features 
      •  REST Based Management 
  Future 



                                                                                                                     A Progress So3ware Company 
 3       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Why Apollo? 




                                                                                                                                    A Progress So3ware Company 
     Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.     FuseSource Confiden6al      A Progress So3ware Company 
4 
Apache Apollo 


                                                                  Goal 
  An experiment to beNer u6lize high core counts on modern 
   processors 

                                                             Resulted
  A completely new broker core that is much more determinis6c, 
   stable, and scaleable 
  Branched as a new project and a chance for a clean start 




                                                                                                                  A Progress So3ware Company 
 5    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Apollo Architecture 




  Reactor Based Thread Model 
  Scala implementa6on 
  Protocol Agnos6c 
  REST Based Management 




                                                                                                                  A Progress So3ware Company 
 6    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
HawtDispatch 




                                                                                                                                    A Progress So3ware Company 
     Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.     FuseSource Confiden6al      A Progress So3ware Company 
7 
HawtDispatch ‐ Introduc6on 




  Small (less than 100k) thread pooling and NIO event no6fica6on 
   framework API 
  hNp://hawtdispatch.fusesource.org/ 
  Java clone of Grand Central Dispatch 
  Avoid explicit usage of threads and synchroniza6on points in 
   mul6threaded applica6ons 
  Applica6on developer submit tasks to dispatch queues 
  Fixed‐sized thread pool execute tasks 



                                                                                                                  A Progress So3ware Company 
 8    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
HawtDispatch ‐ Dispatch Queues 

  Global Dispatch Queue 
      •  3 global queues shared 
      •  Non determinis6c order 
      •  3 priori6es 

                               DispatchQueue queue = getGlobalQueue(HIGH);
                                


  Serial Dispatch Queue 
      •  Serial FIFO queues 
      •  Synchronize certain task execu6ons 

                           DispatchQueue queue = createQueue("My queue");
                            




                                                                                                                     A Progress So3ware Company 
 9       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
HawtDispatch ‐ Submijng Tasks 

  Java                                                             queue.execute(new Runnable(){
                                                                      public void run() {
                                                                         System.out.println("Hi!");
                                                                      }
                                                                    });
  Scala                                                             
                                                                       queue {
                                                                          System.out.println("Hi!");
                                                                       }
                                                                       // or
                                                                       queue.execute(^{
                                                                          System.out.println("Hi!");
  Tasks                                                               })
       •  non‐blocking                                                  
       •  lock‐free 
       •  wait‐free 



                                                                                                                      A Progress So3ware Company 
 10       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
HawtDispatch ‐ Dispatch Sources 

  Trigger a task execu6on based on external event 
  Ideal for dealing with NIO events 

      SelectableChannel channel = ...
      DispatchQueue queue = createQueue()
      DispatchSource source = createSource(channel, OP_READ, queue);
      source.setEventHandler(new Runnable(){
        public void run() {
           ByteBuffer buffer = ByteBuffer.allocate(1024);
           int count;
           while( (c=channel.read(buffer)) > 0 ) {
              // just dump it to the console
              System.out.write(buffer.array(), buffer.offset(), buffer.position());
           }
        }
      });
      source.resume();
       




                                                                                                                    A Progress So3ware Company 
11      Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
HawtDispatch ‐ conclusion 

  Ideal for developing highly concurrent applica6ons 
  Ideal for handling NIO events 
  Ideal for implemen6ng broker cores 
  Impressive performances 




  New development paradigm means it couldn t be fiNed into exis6ng 
   Ac6veMQ broker 



                                                                                                                   A Progress So3ware Company 
 12    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Connec6vity 




                                                                                                                                     A Progress So3ware Company 
      Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.     FuseSource Confiden6al      A Progress So3ware Company 
13 
Message protocols ‐ Overview 



  Broker Core is Protocol Agnos6c  
  Protocols are Plugins 
       •  STOMP 1.0/1.1 
       •  MQTT v3.1 
       •  Openwire 
  Transports are Pluggable too. 
       •  TCP, WebSockets etc. 
  Protocol detec6on (all protocols can use 1 port) 




                                                                                                                      A Progress So3ware Company 
 14       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Feature: Mul6ple Transports 




  TCP 
  SSL  
  WebSockets 
  Secure WebSockets 
  UDP 




                                                                                                                  A Progress So3ware Company 
15    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Stomp ‐ basics 




  hNp://stomp.github.com/ 
  Simple Text Orientated Messaging Protocol 
  HTTP for the messaging realm 
  Very simple, so it s easy to write clients and servers in prac6cally 
   any language 
  A lot of exis6ng clients in C, Ruby, Pyhton, JS, PHP, etc. 
  Provides a way to connect different plamorms in asynchronous way 
  Also Implemented by Ac6veMQ, RabbitMQ, HornetQ, and many 
   others. 


                                                                                                                   A Progress So3ware Company 
 16    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Stomp ‐ Nutshell 

  Based on text frames, similar to 
   HTTP ones                                                                                               MESSAGE
                                                                                                           subscription:0
  Can transport binary bodies                                                                             message-id:007
  Frame command for every                                                                                 destination:/queue/a
                                                                                                           content-type:text/plain
   messaging concept, like CONNECT, 
   MESSAGE, SUBSCRIBE, ACK, etc.                                                                           hello queue a^@
  New in version 1.1 
      •  Protocol nego6a6on 
      •  Heartbeats 
      •  NACK 
      •  Virtual hosts 




                                                                                                                             A Progress So3ware Company 
17       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Apollo and Stomp 

  Both 1.0 and 1.1 Supported 
                                                                                                          SEND
  Des6na6on Types                                                                                        destination:/queue/a
       •  Queues ‐ /queue/a                                                                               receipt:001
       •  Topics ‐ /topic/b	                                                                              persistent: true
       •  Durable Subscrip6ons ‐ /dsub/c 
                                                                                                          hello queue a
                                                                                                          ^@
  Reliable messaging 
                                                                                                          RECEIPT
                                                                                                          receipt-id:001

                                                                                                          ^@




                                                                                                                           A Progress So3ware Company 
 18        Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Apollo and Stomp 



  More messaging features 
      •  Message expira6on 
      •  Topic retained messages 
      •  Topic durable subscrip6ons 
      •  Queue browsing 
      •  Queue message sequences 
      •  Exclusive subscrip6ons 
      •  Temporary des6na6ons 
      •  Des6na6on wildcards 
      •  Composite des6na6ons 
      •  Message selectors 



                                                                                                                     A Progress So3ware Company 
19       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Connec6vity ‐ MQTT 

  Get at hNps://github.com/fusesource/fuse‐extra/ 
  Focused on: 
   •  low bandwidth networks 
   •  unreliable networks 
   •   Small footprint / Embedded Devices 
  3 QoS Op6ons 
  Also Implemented by  
   WebsphereMQ,  
   MosquiNo and  
   others. 
    



                                                                                                                   A Progress So3ware Company 
 20    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Connec6vity – JMS API 

  StompJMS is a JMS 1.1 client implemented using the STOMP 
   protocol. 
  Get it at hNps://github.com/fusesource/stompjms 
  Client implemented with HawtDispatch 
      •  Constant number of threads no maNer how many client connec6ons are 
         established. 

       import org.fusesource.stomp.jms.*;import javax.jms.*;	
       	
       StompJmsConnectionFactory factory = new
       StompJmsConnectionFactory();factory.setBrokerURI("tcp://localhost:
       61613 );	
       Connection connection = factory.createConnection( admin , password );	
       	
       Destination example = new StompJmsDestination( /queue/example );	




                                                                                                                     A Progress So3ware Company 
21       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Connec6vity – OpenWire 

  OpenWire is the na6ve binary protocol implemented by Ac6veMQ 
  API op6ons:  
      •  JMS 1.1 Client of Ac6veMQ 5.x 
      •  NMS Client for C# Apps 
      •  CMS Client for C++ Apps 
  Working Features 
      •  Queues, Topics, Durable Subscrip6ons 
      •  Temporary Des6na6ons 
      •  Transac6ons 
  Not Yet Supported 
      •  XA Transac6ons (distributed transac6ons) 
      •  Network of Brokers style clustering 
      •  0 sized consumer prefetches 

                                                                                                                     A Progress So3ware Company 
22       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
LevelDB Store 




                                                                                                                                     A Progress So3ware Company 
      Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.     FuseSource Confiden6al      A Progress So3ware Company 
23 
Message Store ‐ overview 

  Message Stores are Plugins 
  Ships with 2 Op6ons 
       •  LevelDB Store 
       •  BDB Store 
  Used to store 
       •  persistent messages 
       •  non‐persistent messages that needs to be swapped out of memory 
  Non‐persistent messages that get swapped out do not get dropped 
   on restart 
  Delayed Writes 




                                                                                                                      A Progress So3ware Company 
 24       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
LevelDB ‐ Basics 




  What is LevelDB 
       •  LevelDB is a fast key‐value storage library  
       •  WriNen at Google  
       •  Provides an ordered mapping from string keys to string values 
       •  Based on SSTable and Log Structured Merge (LSM) Trees 




                                                                                                                      A Progress So3ware Company 
 25       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
LevelDB ‐ Basics 




  Designed to efficiently store large numbers of key‐value pairs while 
   op6mizing for high throughput, sequen6al read/write workloads 
  Ideal for implemen6ng message store index 
  Much beNer performance over tradi6onal B‐Tree indexes (used in 
   KahaDB) 




                                                                                                                  A Progress So3ware Company 
26    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
LevelDB ‐ Basics 




  It s a C++ library (no client‐server support) 
  Batching writes 
  Forward and backward itera6on over data 
  Uses Snappy compression 




                                                                                                                   A Progress So3ware Company 
 27    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
LevelDB Store 




  Uses LevelDB to maintain indexes into log files holding the 
   messages 
  Uses a JNI driver on Linux and OS X, but falls back to a pure Java 
   version on other plamorms 
  Supports replica6on to get High Availability 
  Default store in Apollo. Available in Apache Ac6veMQ 5.6.0 




                                                                                                                   A Progress So3ware Company 
 28    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
LevelDB vs KahaDB 




  It maintains fewer index entries per message than KahaDB which 
   means it has a higher persistent throughput. 
  Faster recovery when a broker restarts 
  LevelDB based index provide a much beNer performance than the 
   B‐Tree for sequen6al access 
  LevelDB indexes support concurrent read access 
  Pauseless data log file garbage collec6on cycles 




                                                                                                                  A Progress So3ware Company 
29    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
LevelDB vs KahaDB 




  Uses fewer read IO opera6ons to load stored messages. 
  It will only journal the payload of the message once 
  Exposes it's status via JMX for monitoring 
  Supports replica6on to get High Availability 




                                                                                                                  A Progress So3ware Company 
30    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
LevelDB store ‐ HA 




  HA version of store works with Hadoop based file systems 
  Message log is mirrored to HDFS 
  It can sync on HDFS file instead of local file system 
  LevelDB indexes are immutable on disk (SSTables) 
  On checkpoint .sst files are uploaded to HDFS 




                                                                                                                  A Progress So3ware Company 
31    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
LevelDB store ‐ HA Recovery 




  On master failure, slave will download  
       •  message log 
       •  .sst files associated with the latest uploaded index 
  Con6nue with regular recovery process 




                                                                                                                      A Progress So3ware Company 
 32       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
LevelDB store – HA locking 




  Master elec6on is done externally 
  Mul6ple brokers should never use the same HDFS path 
  Apache ZooKeeper good op6on for implemen6ng distributed 
   locking 
  FuseFabric (hNp://fuse.fusesource.org/fabric/) can be used as well 




                                                                                                                   A Progress So3ware Company 
 33    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
BDB store 



 Not ASL 2.0!  You have to Agree to the BDB 
  license & download from Oracle. 
 Pure Java implementa6on 
 Very robust 
 The BDB library supports advanced features like 
  replica6on (not yet exploited) 




                                                                                                                  A Progress So3ware Company 
34    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Features 




                                                                                                                                     A Progress So3ware Company 
      Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.     FuseSource Confiden6al      A Progress So3ware Company 
35 
Feature: JAAS Authen6ca6on 



 Use any 3rd party JAAS login module 
 Ships with security enabled by default 
  • Default id/password is admin/password 
 File based user and group configura6on 
 Supports IP address white and black lists. 
 X509 Cer6ficates 
 Op6onal guest login support 



                                                                                                                  A Progress So3ware Company 
36    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Feature: Authoriza6on rules 



 Fine grained control of who can 
  • admin, monitor, configure, connect, create, destroy,  
  • send, receive, consume 
 On broker resources like: 
  • broker, connector, virtual host, topic, queue or 
    durable subscrip6ons 
 <access_rule allow="bartenders" action="send,consume                                                                
              kind= queue topic id= BAR.* />
 <access_rule deny="guests" action="consume"/>
  
                                                                                                                  A Progress So3ware Company 
37    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Feature: Config Updates 




 All Configura6on files are watch and changes are applied at 
  run6me: 
  • Broker config: etc/apollo.xml 
  • JAAS config files like: etc/user.proper6es 
  • Logging config: etc/log4j.proper6es 
 No need to restart to apply config changes 




                                                                                                                  A Progress So3ware Company 
38    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Feature: Config Updates 




 All Configura6on files are watch and changes are applied at 
  run6me: 
  • Broker config: etc/apollo.xml 
  • JAAS config files like: etc/user.proper6es 
  • Logging config: etc/log4j.proper6es 
 No need to restart to apply config changes 




                                                                                                                  A Progress So3ware Company 
39    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Feature: REST Management 




 curl -u "admin:password"  

 http://localhost:61680/broker/virtual-hosts/default.json
  




                                                                                                                  A Progress So3ware Company 
40    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Where is it going? 




                                                                                                                                     A Progress So3ware Company 
      Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.     FuseSource Confiden6al      A Progress So3ware Company 
41 
Where has it been? 




                                                                                                                  A Progress So3ware Company 
42    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Feature diff vs Ac6veMQ 


      Missing in Apollo                                                                   Only in Apollo 
       Networks of Brokers                                                                REST Management API 
       Priority Support                                                                   Secure WebSockets 
       Message Groups                                                                     Message Sequences 
       Message Scheduling                                                                 Con6nuous Queue 
       XA Transac6ons                                                                    Browsing  
       JMX Management API                                                                 Run6me Config Updates 
                                                                                           Per Consumer Store 
                                                                                          Prefetch 
                                                                                           
                                                                                            

                                                                                                                      A Progress So3ware Company 
43        Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Future 




  Start integra6ng it in Ac6veMQ  
       •  Apollo should be a new broker engine for 6.0 
       •  We should try to port all exis6ng features (networks, priority queues, XA, etc.) 
  Tons of interes6ng work ahead of us ‐ Join us 




                                                                                                                      A Progress So3ware Company 
 44       Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
Ques6ons? 


  Links: 
    •  Apache Apollo hNp://ac6vemq.apache.org/apollo/ 
    •  STOMP Benchmarks hNp://hiramchirino.com/stomp‐benchmark/ 
    •  MQTT Protocol Plugin for Apollo hNps://github.com/fusesource/fuse‐extra 
    •  HawtDispatch hNp://hawtdispatch.fusesource.org/ 
    •  StompJMS hNps://github.com/fusesource/stompjms 

  Blog:  hNp://www.nighNale.net 


  TwiNer:  
   •  hNp://twiNer.com/dejanb 
   •  hNp://twiNer.com/fusenews 


                                                                                                                   A Progress So3ware Company 
 45    Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  

Introduction to ActiveMQ Apollo

  • 1.
    Introduc6on to Ac6veMQ Apollo  Bosanac Dejan May 2011  A Progress So3ware Company  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.   FuseSource Confiden6al  A Progress So3ware Company  1 
  • 2.
    About me     Bosanac Dejan    Senior So3ware Engineer at FUSESource ‐ hNp://fusesource.com    Apache Ac6veMQ commiNer and PMC member    Co‐author of Ac6veMQ in Ac6on  A Progress So3ware Company  2  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 3.
    What we are going to cover?    Why Apollo?    HawtDispatch   Connec6vity  •  Stomp 1.1, MQTT, JMS, ...    LevelDB Store    Features  •  REST Based Management    Future  A Progress So3ware Company  3  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 4.
    Why Apollo?  A Progress So3ware Company  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.   FuseSource Confiden6al  A Progress So3ware Company  4 
  • 5.
    Apache Apollo  Goal    An experiment to beNer u6lize high core counts on modern  processors  Resulted   A completely new broker core that is much more determinis6c,  stable, and scaleable    Branched as a new project and a chance for a clean start  A Progress So3ware Company  5  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 6.
    Apollo Architecture    Reactor Based Thread Model    Scala implementa6on   Protocol Agnos6c    REST Based Management  A Progress So3ware Company  6  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 7.
    HawtDispatch  A Progress So3ware Company  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.   FuseSource Confiden6al  A Progress So3ware Company  7 
  • 8.
    HawtDispatch ‐ Introduc6on    Small (less than 100k) thread pooling and NIO event no6fica6on  framework API    hNp://hawtdispatch.fusesource.org/    Java clone of Grand Central Dispatch    Avoid explicit usage of threads and synchroniza6on points in  mul6threaded applica6ons    Applica6on developer submit tasks to dispatch queues    Fixed‐sized thread pool execute tasks  A Progress So3ware Company  8  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 9.
    HawtDispatch ‐ Dispatch Queues    Global Dispatch Queue  •  3 global queues shared  •  Non determinis6c order  •  3 priori6es  DispatchQueue queue = getGlobalQueue(HIGH);     Serial Dispatch Queue  •  Serial FIFO queues  •  Synchronize certain task execu6ons  DispatchQueue queue = createQueue("My queue");   A Progress So3ware Company  9  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 10.
    HawtDispatch ‐ Submijng Tasks    Java  queue.execute(new Runnable(){ public void run() { System.out.println("Hi!"); } });   Scala    queue { System.out.println("Hi!"); } // or queue.execute(^{ System.out.println("Hi!");   Tasks  }) •  non‐blocking    •  lock‐free  •  wait‐free  A Progress So3ware Company  10  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 11.
    HawtDispatch ‐ Dispatch Sources    Trigger a task execu6on based on external event    Ideal for dealing with NIO events  SelectableChannel channel = ... DispatchQueue queue = createQueue() DispatchSource source = createSource(channel, OP_READ, queue); source.setEventHandler(new Runnable(){ public void run() { ByteBuffer buffer = ByteBuffer.allocate(1024); int count; while( (c=channel.read(buffer)) > 0 ) { // just dump it to the console System.out.write(buffer.array(), buffer.offset(), buffer.position()); } } }); source.resume();   A Progress So3ware Company  11  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 12.
    HawtDispatch ‐ conclusion    Ideal for developing highly concurrent applica6ons    Ideal for handling NIO events   Ideal for implemen6ng broker cores    Impressive performances    New development paradigm means it couldn t be fiNed into exis6ng  Ac6veMQ broker  A Progress So3ware Company  12  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 13.
    Connec6vity  A Progress So3ware Company  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.   FuseSource Confiden6al  A Progress So3ware Company  13 
  • 14.
    Message protocols ‐ Overview    Broker Core is Protocol Agnos6c     Protocols are Plugins  •  STOMP 1.0/1.1  •  MQTT v3.1  •  Openwire    Transports are Pluggable too.  •  TCP, WebSockets etc.    Protocol detec6on (all protocols can use 1 port)  A Progress So3ware Company  14  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 15.
    Feature: Mul6ple Transports    TCP    SSL    WebSockets    Secure WebSockets    UDP  A Progress So3ware Company  15  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 16.
    Stomp ‐ basics    hNp://stomp.github.com/    Simple Text Orientated Messaging Protocol   HTTP for the messaging realm    Very simple, so it s easy to write clients and servers in prac6cally  any language    A lot of exis6ng clients in C, Ruby, Pyhton, JS, PHP, etc.    Provides a way to connect different plamorms in asynchronous way    Also Implemented by Ac6veMQ, RabbitMQ, HornetQ, and many  others.  A Progress So3ware Company  16  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 17.
    Stomp ‐ Nutshell    Based on text frames, similar to  HTTP ones  MESSAGE subscription:0   Can transport binary bodies  message-id:007   Frame command for every  destination:/queue/a content-type:text/plain messaging concept, like CONNECT,  MESSAGE, SUBSCRIBE, ACK, etc.  hello queue a^@   New in version 1.1  •  Protocol nego6a6on  •  Heartbeats  •  NACK  •  Virtual hosts  A Progress So3ware Company  17  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 18.
    Apollo and Stomp    Both 1.0 and 1.1 Supported  SEND   Des6na6on Types  destination:/queue/a •  Queues ‐ /queue/a  receipt:001 •  Topics ‐ /topic/b persistent: true •  Durable Subscrip6ons ‐ /dsub/c  hello queue a ^@   Reliable messaging  RECEIPT receipt-id:001 ^@ A Progress So3ware Company  18  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 19.
    Apollo and Stomp    More messaging features  •  Message expira6on  •  Topic retained messages  •  Topic durable subscrip6ons  •  Queue browsing  •  Queue message sequences  •  Exclusive subscrip6ons  •  Temporary des6na6ons  •  Des6na6on wildcards  •  Composite des6na6ons  •  Message selectors  A Progress So3ware Company  19  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 20.
    Connec6vity ‐ MQTT    Get at hNps://github.com/fusesource/fuse‐extra/    Focused on:  •  low bandwidth networks  •  unreliable networks  •   Small footprint / Embedded Devices    3 QoS Op6ons    Also Implemented by   WebsphereMQ,   MosquiNo and   others.    A Progress So3ware Company  20  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 21.
    Connec6vity – JMS API    StompJMS is a JMS 1.1 client implemented using the STOMP  protocol.    Get it at hNps://github.com/fusesource/stompjms    Client implemented with HawtDispatch  •  Constant number of threads no maNer how many client connec6ons are  established.  import org.fusesource.stomp.jms.*;import javax.jms.*; StompJmsConnectionFactory factory = new StompJmsConnectionFactory();factory.setBrokerURI("tcp://localhost: 61613 ); Connection connection = factory.createConnection( admin , password ); Destination example = new StompJmsDestination( /queue/example ); A Progress So3ware Company  21  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 22.
    Connec6vity – OpenWire    OpenWire is the na6ve binary protocol implemented by Ac6veMQ    API op6ons:   •  JMS 1.1 Client of Ac6veMQ 5.x  •  NMS Client for C# Apps  •  CMS Client for C++ Apps    Working Features  •  Queues, Topics, Durable Subscrip6ons  •  Temporary Des6na6ons  •  Transac6ons    Not Yet Supported  •  XA Transac6ons (distributed transac6ons)  •  Network of Brokers style clustering  •  0 sized consumer prefetches  A Progress So3ware Company  22  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 23.
    LevelDB Store  A Progress So3ware Company  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.   FuseSource Confiden6al  A Progress So3ware Company  23 
  • 24.
    Message Store ‐ overview    Message Stores are Plugins    Ships with 2 Op6ons  •  LevelDB Store  •  BDB Store    Used to store  •  persistent messages  •  non‐persistent messages that needs to be swapped out of memory    Non‐persistent messages that get swapped out do not get dropped  on restart    Delayed Writes  A Progress So3ware Company  24  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 25.
    LevelDB ‐ Basics    What is LevelDB  •  LevelDB is a fast key‐value storage library   •  WriNen at Google   •  Provides an ordered mapping from string keys to string values  •  Based on SSTable and Log Structured Merge (LSM) Trees  A Progress So3ware Company  25  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 26.
    LevelDB ‐ Basics    Designed to efficiently store large numbers of key‐value pairs while  op6mizing for high throughput, sequen6al read/write workloads    Ideal for implemen6ng message store index    Much beNer performance over tradi6onal B‐Tree indexes (used in  KahaDB)  A Progress So3ware Company  26  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 27.
    LevelDB ‐ Basics    It s a C++ library (no client‐server support)   Batching writes    Forward and backward itera6on over data    Uses Snappy compression  A Progress So3ware Company  27  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 28.
    LevelDB Store    Uses LevelDB to maintain indexes into log files holding the  messages    Uses a JNI driver on Linux and OS X, but falls back to a pure Java  version on other plamorms    Supports replica6on to get High Availability    Default store in Apollo. Available in Apache Ac6veMQ 5.6.0  A Progress So3ware Company  28  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 29.
    LevelDB vs KahaDB    It maintains fewer index entries per message than KahaDB which  means it has a higher persistent throughput.    Faster recovery when a broker restarts    LevelDB based index provide a much beNer performance than the  B‐Tree for sequen6al access    LevelDB indexes support concurrent read access    Pauseless data log file garbage collec6on cycles  A Progress So3ware Company  29  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 30.
    LevelDB vs KahaDB    Uses fewer read IO opera6ons to load stored messages.    It will only journal the payload of the message once   Exposes it's status via JMX for monitoring    Supports replica6on to get High Availability  A Progress So3ware Company  30  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 31.
    LevelDB store ‐ HA    HA version of store works with Hadoop based file systems    Message log is mirrored to HDFS   It can sync on HDFS file instead of local file system    LevelDB indexes are immutable on disk (SSTables)    On checkpoint .sst files are uploaded to HDFS  A Progress So3ware Company  31  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 32.
    LevelDB store ‐ HA Recovery    On master failure, slave will download   •  message log  •  .sst files associated with the latest uploaded index    Con6nue with regular recovery process  A Progress So3ware Company  32  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 33.
    LevelDB store – HA locking    Master elec6on is done externally    Mul6ple brokers should never use the same HDFS path   Apache ZooKeeper good op6on for implemen6ng distributed  locking    FuseFabric (hNp://fuse.fusesource.org/fabric/) can be used as well  A Progress So3ware Company  33  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 34.
    BDB store   Not ASL 2.0!  You have to Agree to the BDB  license & download from Oracle.   Pure Java implementa6on   Very robust   The BDB library supports advanced features like  replica6on (not yet exploited)  A Progress So3ware Company  34  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 35.
    Features  A Progress So3ware Company  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.   FuseSource Confiden6al  A Progress So3ware Company  35 
  • 36.
  • 37.
    Feature: Authoriza6on rules   Fine grained control of who can  • admin, monitor, configure, connect, create, destroy,   • send, receive, consume   On broker resources like:  • broker, connector, virtual host, topic, queue or  durable subscrip6ons  <access_rule allow="bartenders" action="send,consume kind= queue topic id= BAR.* /> <access_rule deny="guests" action="consume"/>   A Progress So3ware Company  37  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 38.
    Feature: Config Updates   All Configura6on files are watch and changes are applied at  run6me:  • Broker config: etc/apollo.xml  • JAAS config files like: etc/user.proper6es  • Logging config: etc/log4j.proper6es   No need to restart to apply config changes  A Progress So3ware Company  38  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 39.
    Feature: Config Updates   All Configura6on files are watch and changes are applied at  run6me:  • Broker config: etc/apollo.xml  • JAAS config files like: etc/user.proper6es  • Logging config: etc/log4j.proper6es   No need to restart to apply config changes  A Progress So3ware Company  39  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 40.
    Feature: REST Management  curl -u"admin:password" 
 http://localhost:61680/broker/virtual-hosts/default.json   A Progress So3ware Company  40  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 41.
    Where is it going?  A Progress So3ware Company  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.   FuseSource Confiden6al  A Progress So3ware Company  41 
  • 42.
    Where has it been?  A Progress So3ware Company  42  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 43.
    Feature diff vs Ac6veMQ  Missing in Apollo  Only in Apollo   Networks of Brokers   REST Management API   Priority Support   Secure WebSockets   Message Groups   Message Sequences   Message Scheduling   Con6nuous Queue   XA Transac6ons  Browsing    JMX Management API   Run6me Config Updates     Per Consumer Store  Prefetch       A Progress So3ware Company  43  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 44.
    Future    Start integra6ng it in Ac6veMQ   •  Apollo should be a new broker engine for 6.0  •  We should try to port all exis6ng features (networks, priority queues, XA, etc.)    Tons of interes6ng work ahead of us ‐ Join us  A Progress So3ware Company  44  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.  
  • 45.
    Ques6ons?    Links:  •  Apache Apollo hNp://ac6vemq.apache.org/apollo/  •  STOMP Benchmarks hNp://hiramchirino.com/stomp‐benchmark/  •  MQTT Protocol Plugin for Apollo hNps://github.com/fusesource/fuse‐extra  •  HawtDispatch hNp://hawtdispatch.fusesource.org/  •  StompJMS hNps://github.com/fusesource/stompjms    Blog:  hNp://www.nighNale.net    TwiNer:   •  hNp://twiNer.com/dejanb  •  hNp://twiNer.com/fusenews  A Progress So3ware Company  45  Copyright © 2011  Progress So3ware Corpora6on and/or its subsidiaries or affiliates. All rights reserved.