SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
Queuing at the Checkout
Bulgaria Web Summit 2015
★Chief Technical Architect at Reward Gateway
★Interested in scalability and engineering
★“PHP addict!”
Who am I?
<html>	
  
	
  	
  <head>	
  
	
  	
  	
  	
  <title>Tutorial</title>	
  
	
  	
  </head>	
  
	
  	
  <body>	
  
	
  	
  	
  	
  <?php	
  echo	
  "<p>Hello	
  World</p>";	
  ?>	
  
	
  	
  </body>	
  
</html>	
  
“Do not wait; the time will never be
'just right.' Start where you stand,
and work with whatever tools you
may have at your command, and
better tools will be found as you go
along.”
American author, Napoleon Hill
(1883-1970)
A modern web application
Modern applications are complex
★Modern web
applications often do
not work in isolation.
★Gone are the days of a
single database
powering everything.
★Integrate with
Facebook, Stripe, etc.
Your application
Facebook
Stripe
Amazon S3Zendesk
Adding an API
★Let’s add a new SOAP
service to our
application.
<?xml	
  version="1.0"?>	
  
<soap:Envelope	
  
xmlns:soap="http://www.w3.org/2001/12/soap-­‐envelope"	
  
soap:encodingStyle="http://www.w3.org/2001/12/soap-­‐encoding">	
  
<soap:Body>	
  
	
  	
  <m:GetName	
  xmlns:m="http://www.example.com/name">	
  
	
  	
  	
  	
  <m:Item>John</m:Item>	
  
	
  	
  </m:GetPrice>	
  
</soap:Body>	
  
</soap:Envelope>	
  
Adding an API
★Let’s add a new SOAP
service to our
application.
★PHP makes this really
easy!<?php	
  
$client	
  =	
  new	
  SoapClient("http://www.example.com/some.wsdl");	
  
echo	
  "Hi	
  "	
  .	
  $client-­‐>name()	
  .	
  "n";	
  
Adding an API
★Let’s add a new SOAP
service to our
application.
★PHP makes this really
easy!
★We can be in
production in two
minutes.
$	
  php	
  client.php	
  
Hi	
  John	
  
$	
  php	
  client.php	
  
Hi	
  Dave	
  
$	
  php	
  client.php	
  
Hi	
  Colin	
  
Maintenance
Performance
Scaling
Poor response times lead to loss of revenue
★The slower your site,
the more likely people
are to give up (“exit”)
★Over 75% of people in
an Akami survey said
they would stop using
a site if it took longer
than 4 seconds.
★The more people who
give up, the less
money you’ll make.
ExitRate
0%
5%
10%
15%
20%
Load Time (secs)
0
.1
1
2
3
What can you do?
TL;DR
★Split your application into bits.
★Keep the predictable bit on the request path.
★Move the unpredictable bit somewhere else.
★Use a message queue to communicate between the two halves.
Message Queue Servers
★There are lots of message queue implementations:
★ RabbitMQ
★ Amazon SQS
★ OpenAMQ
★ ….
★Written in different languages with different tradeoffs.
★Almost all support a protocol called AMQP.
Message Queue Basics
★AMQP has three
concepts.
★Exchanges route
messages using rules
★Queues are where
messages wait for
processing
★Bindings define the
routing rules
Publisher
Publisher
Exchange
Exchange
Queue
Queue
Consumer
Consumer
Consumer
Exchange Rules
★The exchanges
understand three
types of rule:
★ Fanout
★ Direct
★ Topic
★You can create almost
any structure with this
set.
Publisher Exchange Queue Consumer
Consumer
Fanout
Queue
Publisher Exchange Queue Consumer
Direct
Exchange Rules Continued
★The exchanges
understand three
types of rule:
★ Fanout
★ Direct
★ Topic
★You can create almost
any structure with this
set.
Publisher Exchange
Queue Consumer
Consumer
Topic
Queue
lazy.#
*.orange.*
*.*.rabbit
Basic Publisher
<?php	
  
require_once	
  __DIR__	
  .	
  '/vendor/autoload.php';	
  
use	
  PhpAmqpLibConnectionAMQPConnection;	
  
use	
  PhpAmqpLibMessageAMQPMessage;	
  
$connection	
  =	
  new	
  AMQPConnection('localhost',	
  5672,	
  'guest',	
  ‘guest');	
  
$channel	
  =	
  $connection-­‐>channel();	
  
$channel-­‐>queue_declare('hello',	
  false,	
  false,	
  false,	
  false);	
  
$msg	
  =	
  new	
  AMQPMessage('Hello	
  World!');	
  
$channel-­‐>basic_publish($msg,	
  '',	
  'hello');	
  
echo	
  "	
  [x]	
  Sent	
  'Hello	
  World!’n”;	
  
$channel-­‐>close();	
  
$connection-­‐>close();	
  
Basic Consumer
#!/usr/bin/env	
  python	
  
import	
  pika	
  
connection	
  =	
  pika.BlockingConnection(pika.ConnectionParameters(	
  
	
  	
  	
  	
  	
  	
  	
  	
  host='localhost'))	
  
channel	
  =	
  connection.channel()	
  
channel.queue_declare(queue='hello')	
  
print	
  '	
  [*]	
  Waiting	
  for	
  messages.	
  To	
  exit	
  press	
  CTRL+C'	
  
def	
  callback(ch,	
  method,	
  properties,	
  body):	
  
	
  	
  	
  	
  print	
  "	
  [x]	
  Received	
  %r"	
  %	
  (body,)	
  
channel.basic_consume(callback,	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  queue='hello',	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  no_ack=True)	
  
channel.start_consuming()
Still need to handle problems…
★You still have to
monitor your queues.
★Easy to see when
things go wrong.
★More advanced
features let you cope
with this better (e.g.
timeouts on delivery)
QueueSize(messages)
0
250
500
750
1,000
Requests (/secs)
0
10
0
20
0
30
0
Still need to handle crashes…
★What happens when the message queue server crashes?
★ You also still need to worry about your data.
★By default, nothing is saved by RabbitMQ (i.e you lose everything.)
★Pay attention to durability settings when configuring the queues.
Some helpful tools
“Bad API”
★http://badapi.trip.tv
★Allows you to send a request and get a known response back.
★Lets you specify how long to delay the response
★Lets you specify a HTTP error code
★Good for simulating a poorly performing API
“RabbitMQ Simulator”
★http://tryrabbitmq.com
★Single page simulator for RabbitMQ
★Interactive user interface
★Lets you try out all the concepts in this talk and get comfortable with exchanges,
bindings etc.
Conclusion
★Keep your application predictable - move the unpredictable bit out.
★Your integration tests should consider API failures and performance problems.
★Command-Query Response Separation can really help in this area (another talk!)
★We’re hiring! http://rg.co/careers
Questions

Weitere ähnliche Inhalte

Was ist angesagt?

Being a pimp without silverlight
Being a pimp without silverlightBeing a pimp without silverlight
Being a pimp without silverlight
Maarten Balliauw
 
Gearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for Scale
Mike Willbanks
 

Was ist angesagt? (20)

Queue your work
Queue your workQueue your work
Queue your work
 
Build App with Nodejs - YWC Workshop
Build App with Nodejs - YWC WorkshopBuild App with Nodejs - YWC Workshop
Build App with Nodejs - YWC Workshop
 
Gearman, Supervisor and PHP - Job Management with Sanity!
Gearman, Supervisor and PHP - Job Management with Sanity!Gearman, Supervisor and PHP - Job Management with Sanity!
Gearman, Supervisor and PHP - Job Management with Sanity!
 
The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)The Mysteries Of JavaScript-Fu (@media SF Edition)
The Mysteries Of JavaScript-Fu (@media SF Edition)
 
Web Assembly (W3C TPAC presentation)
Web Assembly (W3C TPAC presentation)Web Assembly (W3C TPAC presentation)
Web Assembly (W3C TPAC presentation)
 
Distributed Applications with Perl & Gearman
Distributed Applications with Perl & GearmanDistributed Applications with Perl & Gearman
Distributed Applications with Perl & Gearman
 
Khanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solutionKhanh-Nguyen - Gearman - distributed process solution
Khanh-Nguyen - Gearman - distributed process solution
 
Abusing the Cloud for Fun and Profit
Abusing the Cloud for Fun and ProfitAbusing the Cloud for Fun and Profit
Abusing the Cloud for Fun and Profit
 
The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)The Mysteries Of JavaScript-Fu (@media Europe Edition)
The Mysteries Of JavaScript-Fu (@media Europe Edition)
 
Being a pimp without silverlight
Being a pimp without silverlightBeing a pimp without silverlight
Being a pimp without silverlight
 
Deploying Rails on EC2 using Rubber (Slides Only)
Deploying Rails on EC2 using Rubber (Slides Only)Deploying Rails on EC2 using Rubber (Slides Only)
Deploying Rails on EC2 using Rubber (Slides Only)
 
Gearman: A Job Server made for Scale
Gearman: A Job Server made for ScaleGearman: A Job Server made for Scale
Gearman: A Job Server made for Scale
 
[Back2 basic] from c10k problem to concurrency concept
[Back2 basic] from c10k problem to concurrency concept[Back2 basic] from c10k problem to concurrency concept
[Back2 basic] from c10k problem to concurrency concept
 
Observables - the why, what & how
Observables - the why, what & howObservables - the why, what & how
Observables - the why, what & how
 
Gearman and Perl
Gearman and PerlGearman and Perl
Gearman and Perl
 
Cloud-Native DevOps Engineering
Cloud-Native DevOps EngineeringCloud-Native DevOps Engineering
Cloud-Native DevOps Engineering
 
Gearman and asynchronous processing in PHP applications
Gearman and asynchronous processing in PHP applicationsGearman and asynchronous processing in PHP applications
Gearman and asynchronous processing in PHP applications
 
Ops, DevOps, NoOps and AWS Lambda
Ops, DevOps, NoOps and AWS LambdaOps, DevOps, NoOps and AWS Lambda
Ops, DevOps, NoOps and AWS Lambda
 
Spreadshirt Techcamp 2018 - Hold until Told
Spreadshirt Techcamp 2018 - Hold until ToldSpreadshirt Techcamp 2018 - Hold until Told
Spreadshirt Techcamp 2018 - Hold until Told
 
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)The Mysteries Of JavaScript-Fu (RailsConf Ediition)
The Mysteries Of JavaScript-Fu (RailsConf Ediition)
 

Andere mochten auch

Andere mochten auch (6)

Information security diligence issue 4.5
Information security diligence issue 4.5 Information security diligence issue 4.5
Information security diligence issue 4.5
 
Information for new clients.
Information for new clients.Information for new clients.
Information for new clients.
 
CEO Glenn Elliott's User Manual : A solution for poor employee trust?
CEO Glenn Elliott's User Manual : A solution for poor employee trust?CEO Glenn Elliott's User Manual : A solution for poor employee trust?
CEO Glenn Elliott's User Manual : A solution for poor employee trust?
 
Review: Wellness technology in the workplace
Review: Wellness technology in the workplace Review: Wellness technology in the workplace
Review: Wellness technology in the workplace
 
Total Rewards Strategy- Debra Corey
Total Rewards Strategy- Debra CoreyTotal Rewards Strategy- Debra Corey
Total Rewards Strategy- Debra Corey
 
Bridging the employee engagement gap
Bridging the employee engagement gapBridging the employee engagement gap
Bridging the employee engagement gap
 

Ähnlich wie Queueing at the Checkout

First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
Tomas Cervenka
 

Ähnlich wie Queueing at the Checkout (20)

Challenges behind the scenes of the large Swiss e-Commerce shop apfelkiste.ch...
Challenges behind the scenes of the large Swiss e-Commerce shop apfelkiste.ch...Challenges behind the scenes of the large Swiss e-Commerce shop apfelkiste.ch...
Challenges behind the scenes of the large Swiss e-Commerce shop apfelkiste.ch...
 
Planning to Fail #phpne13
Planning to Fail #phpne13Planning to Fail #phpne13
Planning to Fail #phpne13
 
Ajax and PHP
Ajax and PHPAjax and PHP
Ajax and PHP
 
Otimizando servidores web
Otimizando servidores webOtimizando servidores web
Otimizando servidores web
 
Building Asynchronous Applications
Building Asynchronous ApplicationsBuilding Asynchronous Applications
Building Asynchronous Applications
 
Mazda siv - web services
Mazda   siv - web servicesMazda   siv - web services
Mazda siv - web services
 
Planning to Fail #phpuk13
Planning to Fail #phpuk13Planning to Fail #phpuk13
Planning to Fail #phpuk13
 
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNAFirst Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
First Hive Meetup London 2012-07-10 - Tomas Cervenka - VisualDNA
 
Silverlight vs HTML5 - Lessons learned from the real world...
Silverlight vs HTML5 - Lessons learned from the real world...Silverlight vs HTML5 - Lessons learned from the real world...
Silverlight vs HTML5 - Lessons learned from the real world...
 
AWS re:Invent 2016: Save up to 90% and Run Production Workloads on Spot - Fea...
AWS re:Invent 2016: Save up to 90% and Run Production Workloads on Spot - Fea...AWS re:Invent 2016: Save up to 90% and Run Production Workloads on Spot - Fea...
AWS re:Invent 2016: Save up to 90% and Run Production Workloads on Spot - Fea...
 
Real time web
Real time webReal time web
Real time web
 
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over WebsocketIntroduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
Introduction to WAMP, a protocol enabling PUB/SUB and RPC over Websocket
 
Scaling symfony apps
Scaling symfony appsScaling symfony apps
Scaling symfony apps
 
AWS re:Invent 2016 Fast Forward
AWS re:Invent 2016 Fast ForwardAWS re:Invent 2016 Fast Forward
AWS re:Invent 2016 Fast Forward
 
Ajax Performance
Ajax PerformanceAjax Performance
Ajax Performance
 
AWS Serverless patterns & best-practices in AWS
AWS Serverless  patterns & best-practices in AWSAWS Serverless  patterns & best-practices in AWS
AWS Serverless patterns & best-practices in AWS
 
Do You Need a Service Mesh? @ London Devops, January 2019
Do You Need a Service Mesh? @ London Devops, January 2019Do You Need a Service Mesh? @ London Devops, January 2019
Do You Need a Service Mesh? @ London Devops, January 2019
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
 
AWS Observability Made Simple
AWS Observability Made SimpleAWS Observability Made Simple
AWS Observability Made Simple
 
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
Jeremy Edberg (MinOps ) - How to build a solid infrastructure for a startup t...
 

Kürzlich hochgeladen

Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
UK Journal
 

Kürzlich hochgeladen (20)

Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptxBT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
BT & Neo4j _ How Knowledge Graphs help BT deliver Digital Transformation.pptx
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Your enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4jYour enemies use GenAI too - staying ahead of fraud with Neo4j
Your enemies use GenAI too - staying ahead of fraud with Neo4j
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdfBreaking Down the Flutterwave Scandal What You Need to Know.pdf
Breaking Down the Flutterwave Scandal What You Need to Know.pdf
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 

Queueing at the Checkout

  • 1. Queuing at the Checkout Bulgaria Web Summit 2015
  • 2. ★Chief Technical Architect at Reward Gateway ★Interested in scalability and engineering ★“PHP addict!” Who am I?
  • 3.
  • 4. <html>      <head>          <title>Tutorial</title>      </head>      <body>          <?php  echo  "<p>Hello  World</p>";  ?>      </body>   </html>  
  • 5. “Do not wait; the time will never be 'just right.' Start where you stand, and work with whatever tools you may have at your command, and better tools will be found as you go along.” American author, Napoleon Hill (1883-1970)
  • 6. A modern web application
  • 7. Modern applications are complex ★Modern web applications often do not work in isolation. ★Gone are the days of a single database powering everything. ★Integrate with Facebook, Stripe, etc. Your application Facebook Stripe Amazon S3Zendesk
  • 8. Adding an API ★Let’s add a new SOAP service to our application. <?xml  version="1.0"?>   <soap:Envelope   xmlns:soap="http://www.w3.org/2001/12/soap-­‐envelope"   soap:encodingStyle="http://www.w3.org/2001/12/soap-­‐encoding">   <soap:Body>      <m:GetName  xmlns:m="http://www.example.com/name">          <m:Item>John</m:Item>      </m:GetPrice>   </soap:Body>   </soap:Envelope>  
  • 9. Adding an API ★Let’s add a new SOAP service to our application. ★PHP makes this really easy!<?php   $client  =  new  SoapClient("http://www.example.com/some.wsdl");   echo  "Hi  "  .  $client-­‐>name()  .  "n";  
  • 10. Adding an API ★Let’s add a new SOAP service to our application. ★PHP makes this really easy! ★We can be in production in two minutes. $  php  client.php   Hi  John   $  php  client.php   Hi  Dave   $  php  client.php   Hi  Colin  
  • 11.
  • 15. Poor response times lead to loss of revenue ★The slower your site, the more likely people are to give up (“exit”) ★Over 75% of people in an Akami survey said they would stop using a site if it took longer than 4 seconds. ★The more people who give up, the less money you’ll make. ExitRate 0% 5% 10% 15% 20% Load Time (secs) 0 .1 1 2 3
  • 17. TL;DR ★Split your application into bits. ★Keep the predictable bit on the request path. ★Move the unpredictable bit somewhere else. ★Use a message queue to communicate between the two halves.
  • 18. Message Queue Servers ★There are lots of message queue implementations: ★ RabbitMQ ★ Amazon SQS ★ OpenAMQ ★ …. ★Written in different languages with different tradeoffs. ★Almost all support a protocol called AMQP.
  • 19. Message Queue Basics ★AMQP has three concepts. ★Exchanges route messages using rules ★Queues are where messages wait for processing ★Bindings define the routing rules Publisher Publisher Exchange Exchange Queue Queue Consumer Consumer Consumer
  • 20. Exchange Rules ★The exchanges understand three types of rule: ★ Fanout ★ Direct ★ Topic ★You can create almost any structure with this set. Publisher Exchange Queue Consumer Consumer Fanout Queue Publisher Exchange Queue Consumer Direct
  • 21. Exchange Rules Continued ★The exchanges understand three types of rule: ★ Fanout ★ Direct ★ Topic ★You can create almost any structure with this set. Publisher Exchange Queue Consumer Consumer Topic Queue lazy.# *.orange.* *.*.rabbit
  • 22. Basic Publisher <?php   require_once  __DIR__  .  '/vendor/autoload.php';   use  PhpAmqpLibConnectionAMQPConnection;   use  PhpAmqpLibMessageAMQPMessage;   $connection  =  new  AMQPConnection('localhost',  5672,  'guest',  ‘guest');   $channel  =  $connection-­‐>channel();   $channel-­‐>queue_declare('hello',  false,  false,  false,  false);   $msg  =  new  AMQPMessage('Hello  World!');   $channel-­‐>basic_publish($msg,  '',  'hello');   echo  "  [x]  Sent  'Hello  World!’n”;   $channel-­‐>close();   $connection-­‐>close();  
  • 23. Basic Consumer #!/usr/bin/env  python   import  pika   connection  =  pika.BlockingConnection(pika.ConnectionParameters(                  host='localhost'))   channel  =  connection.channel()   channel.queue_declare(queue='hello')   print  '  [*]  Waiting  for  messages.  To  exit  press  CTRL+C'   def  callback(ch,  method,  properties,  body):          print  "  [x]  Received  %r"  %  (body,)   channel.basic_consume(callback,                                              queue='hello',                                              no_ack=True)   channel.start_consuming()
  • 24. Still need to handle problems… ★You still have to monitor your queues. ★Easy to see when things go wrong. ★More advanced features let you cope with this better (e.g. timeouts on delivery) QueueSize(messages) 0 250 500 750 1,000 Requests (/secs) 0 10 0 20 0 30 0
  • 25. Still need to handle crashes… ★What happens when the message queue server crashes? ★ You also still need to worry about your data. ★By default, nothing is saved by RabbitMQ (i.e you lose everything.) ★Pay attention to durability settings when configuring the queues.
  • 27. “Bad API” ★http://badapi.trip.tv ★Allows you to send a request and get a known response back. ★Lets you specify how long to delay the response ★Lets you specify a HTTP error code ★Good for simulating a poorly performing API
  • 28. “RabbitMQ Simulator” ★http://tryrabbitmq.com ★Single page simulator for RabbitMQ ★Interactive user interface ★Lets you try out all the concepts in this talk and get comfortable with exchanges, bindings etc.
  • 29. Conclusion ★Keep your application predictable - move the unpredictable bit out. ★Your integration tests should consider API failures and performance problems. ★Command-Query Response Separation can really help in this area (another talk!) ★We’re hiring! http://rg.co/careers