SlideShare ist ein Scribd-Unternehmen logo
1 von 51
Downloaden Sie, um offline zu lesen
Scaling Web Apps
                             With RabbitMQ
                              Alvaro Videla - ECUG Con 2010




Thursday, October 21, 2010
About Me

                     •       Development Manager at TheNetCircle.com

                     •       Twitter: @old_sound

                     •       Blog: http://videlalvaro.github.com/

                     •


Thursday, October 21, 2010
Agenda

                     • RabbitMQ
                     • AMQP
                     • Scaling Web Apps
                     • High Availability

Thursday, October 21, 2010
RabbitMQ



Thursday, October 21, 2010
RabbitMQ

                     • Enterprise Messaging System
                     • Open Source MPL
                     • Written in Erlang/OTP
                     • Commercial Support

Thursday, October 21, 2010
Features

                     • Reliable and High Scalable
                     • Easy To install
                     • Easy To Cluster
                     • Runs on: Windows, Solaris, Linux, OSX
                     • AMQP 0.8 - 0.9.1

Thursday, October 21, 2010
Client Libraries

                     • Java
                     • .NET/C#
                     • Erlang
                     • Ruby, Python, PHP, Perl, AS3, Lisp, Scala,
                             Clojure, Haskell



Thursday, October 21, 2010
Docs/Support

                     •       http://www.rabbitmq.com/documentation.html

                     •       http://dev.rabbitmq.com/wiki/

                     •       #rabbitmq at irc.freenode.net

                     •       http://www.rabbitmq.com/email-archive.html




Thursday, October 21, 2010
AMQP



Thursday, October 21, 2010
AMQP
                     • Advanced Message Queuing Protocol
                     • Suits Interoperability
                     • Completely Open Protocol
                     • Binary Protocol
                     • AMQP Model
                     • AMQP Wire Format
Thursday, October 21, 2010
AMQP Model

                     • Exchanges
                     • Message Queues
                     • Bindings
                     • Rules for binding them

Thursday, October 21, 2010
AMQP Wire Protocol


                     • Functional Layer
                     • Transport Layer


Thursday, October 21, 2010
Message Flow




              http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/chap-Messaging_Tutorial-Initial_Concepts.html




Thursday, October 21, 2010
Exchange Types

                     • Fanout
                     • Direct
                     • Topic


Thursday, October 21, 2010
Default Exchanges

                     • amqp.fanout
                     • amqp.direct
                     • amqp.topic


Thursday, October 21, 2010
http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concepts-
                                                                       Fanout_Exchange.html




Thursday, October 21, 2010
http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concepts-
                                                                        Direct_Exchange.html




Thursday, October 21, 2010
http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concepts-
                                                                        Topic_Exchange.html




Thursday, October 21, 2010
Scaling Web Apps



Thursday, October 21, 2010
What means “to Scale”

                     • Scale Up
                     • Scale Down
                     • Scale to New Product Requirements


Thursday, October 21, 2010
Scenario I


                             Batch Processing



Thursday, October 21, 2010
Requirements




Thursday, October 21, 2010
Requirements

                     • Generate XML




Thursday, October 21, 2010
Requirements

                     • Generate XML
                     • Distribution Over a Cluster



Thursday, October 21, 2010
Requirements

                     • Generate XML
                     • Distribution Over a Cluster
                     • Elasticity - Add/Remove new workers


Thursday, October 21, 2010
Design




Thursday, October 21, 2010
Publisher Code
                  $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
                  $channel = $conn->channel();

                  $channel->exchange_declare('video-desc-ex', 'direct', false,
                               true, false);

                  $msg = new AMQPMessage($video_info,
                             array('content_type' => 'text/plain',
                                    'delivery_mode' => 2));

                  $channel->basic_publish($msg, 'video-desc-ex');

                  $channel->close();
                  $conn->close();




Thursday, October 21, 2010
Consumer Code
                  $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
                  $channel = $conn->channel();

                  $channel->exchange_declare('video-desc-ex', 'direct', false,
                               true, false);
                  $channel->queue_declare('video-desc-queue', false, true,
                               false, false);
                  $channel->queue_bind('video-desc-queue', 'video-desc-ex');

                  $channel->basic_consume('video-desc-queue', $consumer_tag,
                               false, false, false, false, $consumer);

                  while(count($channel->callbacks)) {
                      $channel->wait();
                  }



Thursday, October 21, 2010
Scenario II


                             Upload Pictures



Thursday, October 21, 2010
Requirements




Thursday, October 21, 2010
Requirements
                     • Upload Picture




Thursday, October 21, 2010
Requirements
                     • Upload Picture
                     • Reward User




Thursday, October 21, 2010
Requirements
                     • Upload Picture
                     • Reward User
                     • Notify User Friends



Thursday, October 21, 2010
Requirements
                     • Upload Picture
                     • Reward User
                     • Notify User Friends
                     • Resize Picture


Thursday, October 21, 2010
Design




Thursday, October 21, 2010
Publisher Code
                  $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
                  $channel = $conn->channel();

                  $channel->exchange_declare('upload-pictures', 'fanout', false,
                  true, false);

                  $metadata = json_encode(array(
                    'image_id' => $image_id,
                    'user_id' => $user_id,
                    ‘image_path' => $image_path));

                  $msg = new AMQPMessage($metadata, array('content_type' =>
                  'application/json',   'delivery_mode' => 2));

                  $channel->basic_publish($msg, 'upload-pictures');

                  $channel->close();
                  $conn->close();



Thursday, October 21, 2010
Consumer Code
                  $channel->exchange_declare('upload-pictures', 'fanout',
                              false, true, false);

                  $channel->queue_declare('resize-picture', false, true,
                              false, false);

                  $channel->queue_bind('resize-picture', 'upload-pictures');

                  $channel->basic_consume('resize-picture', $consumer_tag,
                              false, false, false, false, $consumer);

                  while(count($channel->callbacks)) {
                    $channel->wait();
                  }




Thursday, October 21, 2010
Consumer Code
                  $consumer = function($msg){
                    $meta = json_decode($msg->body, true);
                  	
                    resize_picture($meta['image_id'], $meta['image_path']);
                  	
                    $msg->delivery_info['channel']->
                      basic_ack($msg->delivery_info['delivery_tag']);

                       if($msg->body == 'quit'){
                         $msg->delivery_info['channel']->
                           basic_cancel($msg->delivery_info['consumer_tag']);
                       }
                  };




Thursday, October 21, 2010
Scenario III


                             Distributed Logging



Thursday, October 21, 2010
Requirements




Thursday, October 21, 2010
Requirements
                     • Several Web Servers




Thursday, October 21, 2010
Requirements
                     • Several Web Servers
                     • Logic Separated by Module/Action




Thursday, October 21, 2010
Requirements
                     • Several Web Servers
                     • Logic Separated by Module/Action
                     • Several Log Levels:



Thursday, October 21, 2010
Requirements
                     • Several Web Servers
                     • Logic Separated by Module/Action
                     • Several Log Levels:
                      • Info
                      • Warning
                      • Error
Thursday, October 21, 2010
Design




Thursday, October 21, 2010
Publisher Code
                  $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
                  $channel = $conn->channel();

                  $channel->exchange_declare('logs', 'topic', false, true, false);

                  $msg = new AMQPMessage('some log message',
                                  array('content_type' => 'text/plain'));

                  $channel->basic_publish($msg, 'logs',
                             server1.user.profile.info');

                  $channel->close();
                  $conn->close();




Thursday, October 21, 2010
Consumer Code

                  $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
                  $channel = $conn->channel();

                  $channel->exchange_declare('logs', 'topic', false,
                                true, false);
                  $channel->queue_declare('server1-logs', false, true,
                                false, false);
                  $channel->queue_bind('server1-logs', 'logs', 'server1.#');




Thursday, October 21, 2010
Consumer Code

                  $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
                  $channel = $conn->channel();

                  $channel->exchange_declare('logs', 'topic', false,
                                true, false);
                  $channel->queue_declare('error-logs', false, true,
                                false, false);
                  $channel->queue_bind('error-logs', 'logs', '#.error');




Thursday, October 21, 2010
One Setup for HA




Thursday, October 21, 2010
Questions?



Thursday, October 21, 2010
Thanks!
                                      Alvaro Videla
                                http://twitter.com/old_sound
                                http://github.com/videlalvaro
                                    http://github.com/tnc
                             http://www.slideshare.net/old_sound




Thursday, October 21, 2010

Weitere ähnliche Inhalte

Ähnlich wie Scaling webappswithrabbitmq

Mobile, Media & Touch
Mobile, Media & TouchMobile, Media & Touch
Mobile, Media & Touch
Tim Wright
 
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP GroupDeveloping Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
minddog
 
NodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time WebNodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time Web
Jakub Nesetril
 
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Guillaume Laforge
 
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume Laforge
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume LaforgeGroovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume Laforge
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume Laforge
Guillaume Laforge
 
Concurrency
ConcurrencyConcurrency
Concurrency
ehuard
 
The Tech Side of Project Argo
The Tech Side of Project ArgoThe Tech Side of Project Argo
The Tech Side of Project Argo
Wesley Lindamood
 
Agile Enterprise Devops and Cloud - Interop 2010 NYC
Agile Enterprise Devops and Cloud - Interop 2010 NYCAgile Enterprise Devops and Cloud - Interop 2010 NYC
Agile Enterprise Devops and Cloud - Interop 2010 NYC
Chef Software, Inc.
 

Ähnlich wie Scaling webappswithrabbitmq (20)

Mobile, Media & Touch
Mobile, Media & TouchMobile, Media & Touch
Mobile, Media & Touch
 
Cocoa for Scientists
Cocoa for ScientistsCocoa for Scientists
Cocoa for Scientists
 
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP GroupDeveloping Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
Developing Plugins on OpenVBX at Greater San Francisco Bay Area LAMP Group
 
NodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time WebNodeJS, CoffeeScript & Real-time Web
NodeJS, CoffeeScript & Real-time Web
 
Bar Camp Auckland - Mongo DB Presentation BCA4
Bar Camp Auckland - Mongo DB Presentation BCA4Bar Camp Auckland - Mongo DB Presentation BCA4
Bar Camp Auckland - Mongo DB Presentation BCA4
 
ScaleCamp 2009 - Last.fm vs Xbox
ScaleCamp 2009 - Last.fm vs XboxScaleCamp 2009 - Last.fm vs Xbox
ScaleCamp 2009 - Last.fm vs Xbox
 
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume LaforgeGaelyk - SpringOne2GX - 2010 - Guillaume Laforge
Gaelyk - SpringOne2GX - 2010 - Guillaume Laforge
 
Developing Distributed Semantic Systems
Developing Distributed Semantic SystemsDeveloping Distributed Semantic Systems
Developing Distributed Semantic Systems
 
Mars - ESUG 2010
Mars - ESUG 2010Mars - ESUG 2010
Mars - ESUG 2010
 
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume Laforge
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume LaforgeGroovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume Laforge
Groovy to infinity and beyond - SpringOne2GX - 2010 - Guillaume Laforge
 
Integrating php withrabbitmq_zendcon
Integrating php withrabbitmq_zendconIntegrating php withrabbitmq_zendcon
Integrating php withrabbitmq_zendcon
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Advanced Data Widgets and Server Integration
Advanced Data Widgets and Server IntegrationAdvanced Data Widgets and Server Integration
Advanced Data Widgets and Server Integration
 
Laying Pipe with Transmogrifier
Laying Pipe with TransmogrifierLaying Pipe with Transmogrifier
Laying Pipe with Transmogrifier
 
Multistream in Janus @ CommCon 2019
Multistream in Janus @ CommCon 2019Multistream in Janus @ CommCon 2019
Multistream in Janus @ CommCon 2019
 
Html5 Apps
Html5 AppsHtml5 Apps
Html5 Apps
 
The Tech Side of Project Argo
The Tech Side of Project ArgoThe Tech Side of Project Argo
The Tech Side of Project Argo
 
Best Practices in Ext GWT
Best Practices in Ext GWTBest Practices in Ext GWT
Best Practices in Ext GWT
 
Agile Enterprise Devops and Cloud - Interop 2010 NYC
Agile Enterprise Devops and Cloud - Interop 2010 NYCAgile Enterprise Devops and Cloud - Interop 2010 NYC
Agile Enterprise Devops and Cloud - Interop 2010 NYC
 
GWT Plus HTML 5
GWT Plus HTML 5GWT Plus HTML 5
GWT Plus HTML 5
 

Mehr von Alvaro Videla

Rabbitmq Boot System
Rabbitmq Boot SystemRabbitmq Boot System
Rabbitmq Boot System
Alvaro Videla
 

Mehr von Alvaro Videla (20)

Improvements in RabbitMQ
Improvements in RabbitMQImprovements in RabbitMQ
Improvements in RabbitMQ
 
Data Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring IntegrationData Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring Integration
 
RabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft ConfRabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft Conf
 
Scaling applications with RabbitMQ at SunshinePHP
Scaling applications with RabbitMQ   at SunshinePHPScaling applications with RabbitMQ   at SunshinePHP
Scaling applications with RabbitMQ at SunshinePHP
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data Ingestion
 
Dissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureDissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal Architecture
 
Introduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal LabsIntroduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal Labs
 
Writing testable code
Writing testable codeWriting testable code
Writing testable code
 
RabbitMQ Hands On
RabbitMQ Hands OnRabbitMQ Hands On
RabbitMQ Hands On
 
Rabbitmq Boot System
Rabbitmq Boot SystemRabbitmq Boot System
Rabbitmq Boot System
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry Bootcamp
 
Cloud Messaging With Cloud Foundry
Cloud Messaging With Cloud FoundryCloud Messaging With Cloud Foundry
Cloud Messaging With Cloud Foundry
 
Taming the rabbit
Taming the rabbitTaming the rabbit
Taming the rabbit
 
Vertx
VertxVertx
Vertx
 
Código Fácil De Testear
Código Fácil De TestearCódigo Fácil De Testear
Código Fácil De Testear
 
Desacoplando aplicaciones
Desacoplando aplicacionesDesacoplando aplicaciones
Desacoplando aplicaciones
 
Messaging patterns
Messaging patternsMessaging patterns
Messaging patterns
 
Theres a rabbit on my symfony
Theres a rabbit on my symfonyTheres a rabbit on my symfony
Theres a rabbit on my symfony
 
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory LiteScaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
 

Kürzlich hochgeladen

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Kürzlich hochgeladen (20)

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 

Scaling webappswithrabbitmq

  • 1. Scaling Web Apps With RabbitMQ Alvaro Videla - ECUG Con 2010 Thursday, October 21, 2010
  • 2. About Me • Development Manager at TheNetCircle.com • Twitter: @old_sound • Blog: http://videlalvaro.github.com/ • Thursday, October 21, 2010
  • 3. Agenda • RabbitMQ • AMQP • Scaling Web Apps • High Availability Thursday, October 21, 2010
  • 5. RabbitMQ • Enterprise Messaging System • Open Source MPL • Written in Erlang/OTP • Commercial Support Thursday, October 21, 2010
  • 6. Features • Reliable and High Scalable • Easy To install • Easy To Cluster • Runs on: Windows, Solaris, Linux, OSX • AMQP 0.8 - 0.9.1 Thursday, October 21, 2010
  • 7. Client Libraries • Java • .NET/C# • Erlang • Ruby, Python, PHP, Perl, AS3, Lisp, Scala, Clojure, Haskell Thursday, October 21, 2010
  • 8. Docs/Support • http://www.rabbitmq.com/documentation.html • http://dev.rabbitmq.com/wiki/ • #rabbitmq at irc.freenode.net • http://www.rabbitmq.com/email-archive.html Thursday, October 21, 2010
  • 10. AMQP • Advanced Message Queuing Protocol • Suits Interoperability • Completely Open Protocol • Binary Protocol • AMQP Model • AMQP Wire Format Thursday, October 21, 2010
  • 11. AMQP Model • Exchanges • Message Queues • Bindings • Rules for binding them Thursday, October 21, 2010
  • 12. AMQP Wire Protocol • Functional Layer • Transport Layer Thursday, October 21, 2010
  • 13. Message Flow http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/chap-Messaging_Tutorial-Initial_Concepts.html Thursday, October 21, 2010
  • 14. Exchange Types • Fanout • Direct • Topic Thursday, October 21, 2010
  • 15. Default Exchanges • amqp.fanout • amqp.direct • amqp.topic Thursday, October 21, 2010
  • 19. Scaling Web Apps Thursday, October 21, 2010
  • 20. What means “to Scale” • Scale Up • Scale Down • Scale to New Product Requirements Thursday, October 21, 2010
  • 21. Scenario I Batch Processing Thursday, October 21, 2010
  • 23. Requirements • Generate XML Thursday, October 21, 2010
  • 24. Requirements • Generate XML • Distribution Over a Cluster Thursday, October 21, 2010
  • 25. Requirements • Generate XML • Distribution Over a Cluster • Elasticity - Add/Remove new workers Thursday, October 21, 2010
  • 27. Publisher Code $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST); $channel = $conn->channel(); $channel->exchange_declare('video-desc-ex', 'direct', false, true, false); $msg = new AMQPMessage($video_info, array('content_type' => 'text/plain', 'delivery_mode' => 2)); $channel->basic_publish($msg, 'video-desc-ex'); $channel->close(); $conn->close(); Thursday, October 21, 2010
  • 28. Consumer Code $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST); $channel = $conn->channel(); $channel->exchange_declare('video-desc-ex', 'direct', false, true, false); $channel->queue_declare('video-desc-queue', false, true, false, false); $channel->queue_bind('video-desc-queue', 'video-desc-ex'); $channel->basic_consume('video-desc-queue', $consumer_tag, false, false, false, false, $consumer); while(count($channel->callbacks)) { $channel->wait(); } Thursday, October 21, 2010
  • 29. Scenario II Upload Pictures Thursday, October 21, 2010
  • 31. Requirements • Upload Picture Thursday, October 21, 2010
  • 32. Requirements • Upload Picture • Reward User Thursday, October 21, 2010
  • 33. Requirements • Upload Picture • Reward User • Notify User Friends Thursday, October 21, 2010
  • 34. Requirements • Upload Picture • Reward User • Notify User Friends • Resize Picture Thursday, October 21, 2010
  • 36. Publisher Code $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST); $channel = $conn->channel(); $channel->exchange_declare('upload-pictures', 'fanout', false, true, false); $metadata = json_encode(array( 'image_id' => $image_id, 'user_id' => $user_id, ‘image_path' => $image_path)); $msg = new AMQPMessage($metadata, array('content_type' => 'application/json', 'delivery_mode' => 2)); $channel->basic_publish($msg, 'upload-pictures'); $channel->close(); $conn->close(); Thursday, October 21, 2010
  • 37. Consumer Code $channel->exchange_declare('upload-pictures', 'fanout', false, true, false); $channel->queue_declare('resize-picture', false, true, false, false); $channel->queue_bind('resize-picture', 'upload-pictures'); $channel->basic_consume('resize-picture', $consumer_tag, false, false, false, false, $consumer); while(count($channel->callbacks)) { $channel->wait(); } Thursday, October 21, 2010
  • 38. Consumer Code $consumer = function($msg){ $meta = json_decode($msg->body, true); resize_picture($meta['image_id'], $meta['image_path']); $msg->delivery_info['channel']-> basic_ack($msg->delivery_info['delivery_tag']); if($msg->body == 'quit'){ $msg->delivery_info['channel']-> basic_cancel($msg->delivery_info['consumer_tag']); } }; Thursday, October 21, 2010
  • 39. Scenario III Distributed Logging Thursday, October 21, 2010
  • 41. Requirements • Several Web Servers Thursday, October 21, 2010
  • 42. Requirements • Several Web Servers • Logic Separated by Module/Action Thursday, October 21, 2010
  • 43. Requirements • Several Web Servers • Logic Separated by Module/Action • Several Log Levels: Thursday, October 21, 2010
  • 44. Requirements • Several Web Servers • Logic Separated by Module/Action • Several Log Levels: • Info • Warning • Error Thursday, October 21, 2010
  • 46. Publisher Code $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST); $channel = $conn->channel(); $channel->exchange_declare('logs', 'topic', false, true, false); $msg = new AMQPMessage('some log message', array('content_type' => 'text/plain')); $channel->basic_publish($msg, 'logs', server1.user.profile.info'); $channel->close(); $conn->close(); Thursday, October 21, 2010
  • 47. Consumer Code $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST); $channel = $conn->channel(); $channel->exchange_declare('logs', 'topic', false, true, false); $channel->queue_declare('server1-logs', false, true, false, false); $channel->queue_bind('server1-logs', 'logs', 'server1.#'); Thursday, October 21, 2010
  • 48. Consumer Code $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST); $channel = $conn->channel(); $channel->exchange_declare('logs', 'topic', false, true, false); $channel->queue_declare('error-logs', false, true, false, false); $channel->queue_bind('error-logs', 'logs', '#.error'); Thursday, October 21, 2010
  • 49. One Setup for HA Thursday, October 21, 2010
  • 51. Thanks! Alvaro Videla http://twitter.com/old_sound http://github.com/videlalvaro http://github.com/tnc http://www.slideshare.net/old_sound Thursday, October 21, 2010