Integrating RabbitMQ with PHP
-
Upload
alvaro-videla -
Category
Technology
-
view
33.478 -
download
1
description
Transcript of Integrating RabbitMQ with PHP
Integrating RabbitMQ with PHP
Álvaro Videla
June 2010 - IPC Spring Edition - Berlin
Wednesday, June 2, 2010
About Me
• Lead Developer at TheNetCircle.com
• Writing “RabbitMQ in Action” for Manning
• Twitter: @old_sound
• Blog: http://obvioushints.blogspot.com/
Wednesday, June 2, 2010
The Interoperability
Problem
Wednesday, June 2, 2010
The Problem
MoviePublisher
Wednesday, June 2, 2010
The Problem
NewMovie
MoviePublisher
Wednesday, June 2, 2010
The ProblemWebService
XMLJava
NewMovie
MoviePublisher
Wednesday, June 2, 2010
The ProblemWebService
XML
Image ThumbnailGenerator
C++
Java
NewMovie
MoviePublisher
Wednesday, June 2, 2010
The ProblemWebService
XML
Image ThumbnailGenerator
PHP CacheGenerator
C++
PHP
Java
NewMovie
MoviePublisher
Wednesday, June 2, 2010
The ProblemWebService
XML
Image ThumbnailGenerator
PHP CacheGenerator
StaticHTML
Publisher
C++
PHP
PHP
Java
NewMovie
MoviePublisher
Wednesday, June 2, 2010
The ProblemWebService
XML
Image ThumbnailGenerator
PHP CacheGenerator
StaticHTML
Publisher
C++
PHP
PHP
Java
TrailersGenerator
C++
NewMovie
MoviePublisher
Wednesday, June 2, 2010
SYSTEMSThe ProblemWebService
XML
Image ThumbnailGenerator
PHP CacheGenerator
TrailersGenerator
StaticHTML
Publisher
Wednesday, June 2, 2010
SYSTEMSThe ProblemWebService
XML
Image ThumbnailGenerator
PHP CacheGenerator
TrailersGenerator
StaticHTML
Publisher
Written In Different Languages
Wednesday, June 2, 2010
SYSTEMSThe ProblemWebService
XML
Image ThumbnailGenerator
PHP CacheGenerator
TrailersGenerator
StaticHTML
Publisher
Written In Different Languages
Different Operating Systems
Wednesday, June 2, 2010
SYSTEMSThe ProblemWebService
XML
Image ThumbnailGenerator
PHP CacheGenerator
TrailersGenerator
StaticHTML
Publisher
Written In Different Languages
Different Operating Systems
Written By Different People
Wednesday, June 2, 2010
SYSTEMSThe ProblemWebService
XML
Image ThumbnailGenerator
PHP CacheGenerator
TrailersGenerator
StaticHTML
Publisher
Written In Different Languages
Different Operating Systems
Written By Different People
They Need To Share Information
Wednesday, June 2, 2010
SYSTEMSThe ProblemWebService
XML
Image ThumbnailGenerator
PHP CacheGenerator
TrailersGenerator
StaticHTML
Publisher
Written In Different Languages
Different Operating Systems
Written By Different People
They Need To Share Information
They Need Real Time Data
Wednesday, June 2, 2010
SYSTEMSThe ProblemWebService
XML
Image ThumbnailGenerator
PHP CacheGenerator
TrailersGenerator
StaticHTML
Publisher
Written In Different Languages
Different Operating Systems
Written By Different People
They Need To Share Information
They Need Real Time Data
They Need To Scale
Wednesday, June 2, 2010
Is There a Solution?
Wednesday, June 2, 2010
AMQPand
RabbitMQ
Wednesday, June 2, 2010
AMQP
• Advanced Message Queuing Protocol
• Suits Interoperability
• Completely Open Protocol
• Binary Protocol
• AMQP Model
• AMQP Wire Format
Wednesday, June 2, 2010
AMQP Model
• Exchanges
• Message Queues
• Bindings
• Rules for binding them
Wednesday, June 2, 2010
AMQP Wire Protocol
• Functional Layer
• Transport Layer
Wednesday, June 2, 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
Wednesday, June 2, 2010
Exchange Types
• Fanout
• Direct
• Topic
Wednesday, June 2, 2010
Default Exchanges
• amqp.fanout
• amqp.direct
• amqp.topic
Wednesday, June 2, 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
Wednesday, June 2, 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
Wednesday, June 2, 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
Wednesday, June 2, 2010
Sample usage
Wednesday, June 2, 2010
Sample Usage II
Wednesday, June 2, 2010
Other Advantages
• Fire and Forget
• Stop/Start consumers safely (no need for last processed id)
• No need for Cronjobs locks
• Load Distribution
• Transactions
Wednesday, June 2, 2010
RabbitMQ
Wednesday, June 2, 2010
RabbitMQ
• Enterprise Messaging System
• Open Source MPL
• Written in Erlang/OTP
• Commercial Support
Wednesday, June 2, 2010
Features
• Reliable and High Scalable
• Easy To install
• Easy To Cluster
• Runs on: Windows, Solaris, Linux, OSX
• AMQP 0.8
Wednesday, June 2, 2010
Client Libraries
• Java
• .NET/C#
• Erlang
• Ruby, Python, PHP, Perl, AS3, Lisp, Scala
Wednesday, June 2, 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
Wednesday, June 2, 2010
Our Setup:
Publishers - 28 PHP Frontend Machines
2 PHP Machinesrunning 24 consumers each
Wednesday, June 2, 2010
Our Setup
• Deployed in mid 2009
• Reduced site SPOF
• 500.000+ messages routed a day (and increasing)
• Very easy to install/deploy
Wednesday, June 2, 2010
Easy To Install?
Wednesday, June 2, 2010
Easy To Install?
http://gist.github.com/334219
Wednesday, June 2, 2010
PHP Integration
• http://code.google.com/p/php-amqplib/
• http://code.google.com/p/php-amqp/
• http://code.google.com/p/php-rabbit/
Wednesday, June 2, 2010
Show me the code!
Wednesday, June 2, 2010
RabbitMQ “Hello World!”
Wednesday, June 2, 2010
AMQP Producer
Wednesday, June 2, 2010
AMQP Producer
Wednesday, June 2, 2010
AMQP Producer
Wednesday, June 2, 2010
AMQP Producer
Wednesday, June 2, 2010
AMQP Producer
Wednesday, June 2, 2010
AMQP Consumer
Wednesday, June 2, 2010
AMQP Consumer
Wednesday, June 2, 2010
AMQP Consumer
Wednesday, June 2, 2010
AMQP Consumer
Wednesday, June 2, 2010
AMQP Consumer
Wednesday, June 2, 2010
AMQP Consumer
Wednesday, June 2, 2010
AMQP Consumer
Wednesday, June 2, 2010
RabbitMQ RPC Example
Wednesday, June 2, 2010
RPC Client
Wednesday, June 2, 2010
RPC Client
Wednesday, June 2, 2010
RPC Client
Wednesday, June 2, 2010
RPC Client
Wednesday, June 2, 2010
RPC Client
Wednesday, June 2, 2010
RPC Server
Wednesday, June 2, 2010
RPC Server
Wednesday, June 2, 2010
RPC Server
Wednesday, June 2, 2010
RPC Server
Wednesday, June 2, 2010
RPC Server
Wednesday, June 2, 2010
RPC Server
Wednesday, June 2, 2010
RPC Server
Wednesday, June 2, 2010
Resources:
• http://www.rabbitmq.com/
• https://www.amqp.org/confluence/display/AMQP/About+AMQP
• http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/index.html
• http://wso2.org/library/articles/using-axis2-c-amqp-transport-part-i
• http://www.skaag.net/2010/03/12/rabbitmq-for-beginners/
• http://github.com/bkw/php-amqp
Wednesday, June 2, 2010
Questions?
Wednesday, June 2, 2010
Thanks!Alvaro Videla
http://twitter.com/old_sound
http://www.slideshare.net/old_sound
Wednesday, June 2, 2010