Evented Applications
with RabbitMQ , Python, and CakePHP
What the wibblefish?

All about offloading work, and doing things in
‘realtime’
Make applications that complete tasks in a
distributed/scalable fashion.
Doing work outside the request/response cycle
of a UI/API.
Work to offload

Noti cations (SMS, Email, Postal mail).
Logging.
Import & export.
Process image & video.
Reporting.
Webhooks.
Isn’t cron good enough?



Cron tabs are great with one server.
Cron doesn’t scale to multiple machines.
Cron doesn’t solve the whole problem space.
Problems with Cron


Isn’t suitable for ‘real-time’ results.
Requires a set schedule. You might spin up
processes that do nothing. Or you might not
have enough capacity.
Parallelizing is a pain.
Queues to the rescue!


Queues accept and dispatch events.
Events can contain almost anything*.
Events can be roughly equal to ‘jobs’.
A single event can trigger lots of downstream
work.
Architectural benefits

Separation of concerns.
Collection of mini/small applications.
No monolithic applications.
Decoupled, and easier to test.
Easy to scale. Busy service = more of them.
Queue technologies

RabbitMQ
ZeroMQ
SQS
Celery
Gearman
RabbitMQ

Written in Erlang.
Open source and Free.
Really Fast.
Socket protocol that is has cheap connections.
Data persists after a crash.
Queue basics



Producers create events.
Consumers eat messages, and do work.
messages == events.
Queue Basics



Producer
Queue Basics



Producer
Queue Basics



Producer                  Consumer
Queue Basics

                          Consumer



Producer                    Consumer
Queue Basics

                          Consumer



Producer                    Consumer



                          Consumer
Exchanges

Exchanges abstract queues from the producer.
Route messages to queues, that are bound by
routing keys.
Allows consumers to listen to speci c routing
keys.
Multiple consumers can listen to the same
events.
Exchanges



Producer
Exchanges



Producer
Exchanges
               page_view

                           Consumer



Producer
Exchanges
               page_view

                           Consumer



                  import    Consumer
Producer
Exchanges
                 page_view

                              Consumer



                     import    Consumer
Producer



                              Consumer
               error,
              page_view
Topic subscription


Consumers can also listen to topics. Which are
keys separated by dots.
e.g page_view.search, page_view.update
Consumer could listen to page_view.*
Producing



Can create messages with many tools.
PHP, python, node, ruby, etc.
Messages can contain any stringy data (JSON)
Data for messages


Only string-y things can be stored in messages.
JSON encoded data in message.
Key to value stored in Redis/Memcache.
Keep messages small. RabbitMQ performs
better with small messages.
Consuming


Use a daemon process.
Daemons in PHP can be done, but they kinda
suck.
Usually use sleep(2) or other workaround.
sleep(2) moves you away from ‘real time’.
Aw bugger..
Use a better tool


Other tools are much better for making
daemons.
 Python (pika, kombu, sparkplug)
 NodeJS (node-amqp)
 Ruby (carrot, ruby-amqp)
Managing mixed applications



Many ways to get it done.
Avoid duplicating code.
Thin daemons + worker processes.
Thin daemons


Python/node daemon accepts messages.
Delegate to PHP worker processes.
Keeps PHP’s fork + die work ow.
Re-use application code by calling shells.
Thin daemons



PHP
Thin daemons



PHP
Thin daemons

               Py


PHP
Thin daemons

               Py


PHP            Py
Thin daemons

               Py


PHP            Py


               Py
Thin daemons

               Py    PHP


PHP            Py


               Py
Thin daemons

               Py    PHP


PHP            Py    PHP


               Py
Thin daemons

               Py    PHP


PHP            Py    PHP


               Py    PHP
Demo Time
Overview



Use CakeLog to re events.
Use CakePHP shell’s for actual work.
Thin python daemon for processing messages.
Python + sparkplug



Python module for creating queue listeners.
Created by a developer at FreshBooks.
Ini con guration le de nes behaviour.
What we’ll try:



User events logged during application.
Log events to the database.
Insert code
Limitations of using shells


Daemon and shell processes have to be on the
same box.
This can be limiting as you scale, depends on
how you structure applications.
Solutions


Use HTTP.
Have thin daemons dispatch back to the front-
end application using HTTP.
Use Basic/Digest authentication.
Use checksums.
HTTP daemons



PHP
HTTP daemons



PHP
HTTP daemons



PHP            Py
HTTP daemons


                     Web


PHP            Py
HTTP daemons


                     Web


PHP            Py      Web
HTTP daemons


                     Web


PHP            Py      Web


                      Web
Thanks; Questions?

More Related Content

PDF
Ch ch-changes cake php2
PDF
CakePHP mistakes made
PDF
Getting modern with logging via log4perl
PDF
Getting big without getting fat, in perl
PDF
Learning Puppet Chapter 1
PPTX
Xdebug
PDF
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
PDF
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it
Ch ch-changes cake php2
CakePHP mistakes made
Getting modern with logging via log4perl
Getting big without getting fat, in perl
Learning Puppet Chapter 1
Xdebug
Grand Rapids PHP Meetup: Behavioral Driven Development with Behat
Drupal 8: Huge wins, a Bigger Community, and why you (and I) will Love it

What's hot (20)

PDF
Cooking Perl with Chef: Real World Tutorial with Jitterbug
PDF
Web Hooks
PDF
Master the New Core of Drupal 8 Now: with Symfony and Silex
PDF
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
PDF
PECL Picks - Extensions to make your life better
PDF
How WebHooks Will Make Us All Programmers
PDF
Puppet at GitHub / ChatOps
PDF
Puppet at Pinterest
PDF
Rspec API Documentation
PPTX
Cooking environments with chef
PDF
APIs That Make Things Happen
PDF
Puppet for SysAdmins
PDF
Low maintenance perl notes
PDF
Cooking Perl with Chef
PPTX
React in production
PDF
Writing Software not Code with Cucumber
PPTX
Distributed Applications with Perl & Gearman
PDF
Gearman and Perl
PDF
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
PDF
Maven 3.0 at Øredev
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Web Hooks
Master the New Core of Drupal 8 Now: with Symfony and Silex
Don't RTFM, WTFM - Open Source Documentation - German Perl Workshop 2010
PECL Picks - Extensions to make your life better
How WebHooks Will Make Us All Programmers
Puppet at GitHub / ChatOps
Puppet at Pinterest
Rspec API Documentation
Cooking environments with chef
APIs That Make Things Happen
Puppet for SysAdmins
Low maintenance perl notes
Cooking Perl with Chef
React in production
Writing Software not Code with Cucumber
Distributed Applications with Perl & Gearman
Gearman and Perl
High Quality Symfony Bundles tutorial - Dutch PHP Conference 2014
Maven 3.0 at Øredev
Ad

Similar to Evented applications with RabbitMQ and CakePHP (20)

PDF
RabbitMQ with python and ruby RuPy 2009
PDF
Queue Everything and Please Everyone
PDF
Life in a Queue - Using Message Queue with django
ODP
The Art of Message Queues - TEKX
KEY
Real time system_performance_mon
KEY
High scale flavour
PDF
Lindsay distributed geventzmq
KEY
Cooking a rabbit pie
PDF
Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...
PDF
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
PDF
On Rabbits and Elephants
ODP
Introduction to Python Celery
PPTX
Luxun a Persistent Messaging System Tailored for Big Data Collecting & Analytics
ZIP
Message Queues in Ruby - An Overview
PDF
Celery: The Distributed Task Queue
PDF
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
PDF
Erlang factory slides
PDF
Erlang factory slides
PDF
%w(map reduce).first - A Tale About Rabbits, Latency, and Slim Crontabs
ODP
Inter-Process/Task Communication With Message Queues
RabbitMQ with python and ruby RuPy 2009
Queue Everything and Please Everyone
Life in a Queue - Using Message Queue with django
The Art of Message Queues - TEKX
Real time system_performance_mon
High scale flavour
Lindsay distributed geventzmq
Cooking a rabbit pie
Website Monitoring with Distributed Messages/Tasks Processing (AMQP & RabbitM...
Distributed and concurrent programming with RabbitMQ and EventMachine Rails U...
On Rabbits and Elephants
Introduction to Python Celery
Luxun a Persistent Messaging System Tailored for Big Data Collecting & Analytics
Message Queues in Ruby - An Overview
Celery: The Distributed Task Queue
Asynchronous Architectures for Implementing Scalable Cloud Services - Evan Co...
Erlang factory slides
Erlang factory slides
%w(map reduce).first - A Tale About Rabbits, Latency, and Slim Crontabs
Inter-Process/Task Communication With Message Queues
Ad

More from markstory (20)

PDF
Dependency injection in CakePHP
PDF
Safer, More Helpful CakePHP
PDF
CakePHP - The Road Ahead
PDF
Future of HTTP in CakePHP
PDF
CakePHP mistakes made 2015
PDF
New in cakephp3
PDF
PHP WTF
PDF
CakePHP 3.0 and beyond
PDF
CakePHP mistakes made confoo 2015
PDF
Performance and optimization CakeFest 2014
PDF
Road to CakePHP 3.0
PDF
Performance and optimization
PDF
OWASP Top 10 2013
PDF
CakePHP the yum & yuck
PDF
Introduction to Twig
PDF
Owasp top 10
PDF
Simple search with elastic search
PDF
Making the most of 2.2
PDF
Intro to continuous integration
PDF
PHPunit and you
Dependency injection in CakePHP
Safer, More Helpful CakePHP
CakePHP - The Road Ahead
Future of HTTP in CakePHP
CakePHP mistakes made 2015
New in cakephp3
PHP WTF
CakePHP 3.0 and beyond
CakePHP mistakes made confoo 2015
Performance and optimization CakeFest 2014
Road to CakePHP 3.0
Performance and optimization
OWASP Top 10 2013
CakePHP the yum & yuck
Introduction to Twig
Owasp top 10
Simple search with elastic search
Making the most of 2.2
Intro to continuous integration
PHPunit and you

Recently uploaded (20)

PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PDF
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
PDF
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...
PDF
Introduction to MCP and A2A Protocols: Enabling Agent Communication
PPTX
SGT Report The Beast Plan and Cyberphysical Systems of Control
PDF
Ensemble model-based arrhythmia classification with local interpretable model...
PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PDF
Electrocardiogram sequences data analytics and classification using unsupervi...
PDF
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
PDF
Human Computer Interaction Miterm Lesson
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PPTX
Module 1 Introduction to Web Programming .pptx
giants, standing on the shoulders of - by Daniel Stenberg
Dell Pro Micro: Speed customer interactions, patient processing, and learning...
NewMind AI Weekly Chronicles – August ’25 Week IV
IT-ITes Industry bjjbnkmkhkhknbmhkhmjhjkhj
“The Future of Visual AI: Efficient Multimodal Intelligence,” a Keynote Prese...
Introduction to MCP and A2A Protocols: Enabling Agent Communication
SGT Report The Beast Plan and Cyberphysical Systems of Control
Ensemble model-based arrhythmia classification with local interpretable model...
Build automations faster and more reliably with UiPath ScreenPlay
Rapid Prototyping: A lecture on prototyping techniques for interface design
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
Electrocardiogram sequences data analytics and classification using unsupervi...
MENA-ECEONOMIC-CONTEXT-VC MENA-ECEONOMIC
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
zbrain.ai-Scope Key Metrics Configuration and Best Practices.pdf
Human Computer Interaction Miterm Lesson
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
Module 1 Introduction to Web Programming .pptx

Evented applications with RabbitMQ and CakePHP