Theres a Rabbit                          on my Symfony                            RabbitMQ and Symfony2 Integration       ...
Who?Thursday, March 3, 2011
About Me                    •     Development Manager at TheNetCircle.com                    •     Blog: http://videlalvar...
About Me                    •     Developer at Liip                    •     Blog: http://videlalvaro.github.com/         ...
About Me                          Co-authoring               RabbitMQ in Action              http://bit.ly/rabbitmqThursda...
Why Do I need                           RabbitMQ?Thursday, March 3, 2011
OrThursday, March 3, 2011
Why Do I need                           Messaging?Thursday, March 3, 2011
An Upload Picture                           Form as seen by:Thursday, March 3, 2011
The UserThursday, March 3, 2011
I don’t want to wait                          till your app resizes                                my image!Thursday, Marc...
The Product OwnerThursday, March 3, 2011
Can we also notify the                    user friends when she                    uploads a new image?Thursday, March 3, ...
Can we also notify the                    user friends when she                    uploads a new image?       I forgot to ...
The SysadminThursday, March 3, 2011
Dumb! You’re delivering                    full size images!                 The bandwidth bill has                       ...
Dumb! You’re delivering                    full size images!                 The bandwidth bill has                       ...
The Developer in the                              other teamThursday, March 3, 2011
I need to call your PHP                   stuff but from PythonThursday, March 3, 2011
I need to call your PHP                   stuff but from Python                          And also Java starting next weekT...
YouThursday, March 3, 2011
FML!Thursday, March 3, 2011
Is there a solution?Thursday, March 3, 2011
RabbitMQ & AMQPThursday, March 3, 2011
AMQPThursday, March 3, 2011
AMQP                    • Advanced Message Queuing Protocol                    • Suits Interoperability                   ...
AMQP Model                    • Exchanges                    • Message Queues                    • Bindings               ...
AMQP Wire Protocol                    • Functional Layer                    • Transport LayerThursday, March 3, 2011
Message Flow                  http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/chap-Mes...
Exchange Types                    • Fanout                    • Direct                    • TopicThursday, March 3, 2011
http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concep...
http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concep...
http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concep...
Usage ScenariosThursday, March 3, 2011
Usage Scenarios                    • Batch ProcessingThursday, March 3, 2011
Usage Scenarios                    • Batch Processing                    • Image UploadingThursday, March 3, 2011
Usage Scenarios                    • Batch Processing                    • Image Uploading                    • Distribute...
Scenario                          Batch ProcessingThursday, March 3, 2011
RequirementsThursday, March 3, 2011
Requirements                    • Generate XMLThursday, March 3, 2011
Requirements                    • Generate XML                    • Distribution Over a ClusterThursday, March 3, 2011
Requirements                    • Generate XML                    • Distribution Over a Cluster                    • Elast...
Requirements                    • Generate XML                    • Distribution Over a Cluster                    • Elast...
DesignThursday, March 3, 2011
Publisher Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn...
Publisher Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn...
Publisher Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn...
Publisher Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn...
Publisher Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn...
Publisher Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn...
Consumer Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn-...
Consumer Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn-...
Consumer Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn-...
Consumer Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn-...
Consumer Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn-...
Consumer Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn-...
Consumer Code                 $conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);                 $channel = $conn-...
Scenario                          Upload PicturesThursday, March 3, 2011
RequirementsThursday, March 3, 2011
Requirements                    • Upload PictureThursday, March 3, 2011
Requirements                    • Upload Picture                    • Reward UserThursday, March 3, 2011
Requirements                    • Upload Picture                    • Reward User                    • Notify User Friends...
Requirements                    • Upload Picture                    • Reward User                    • Notify User Friends...
Requirements                    • Upload Picture                    • Reward User                    • Notify User Friends...
DesignThursday, March 3, 2011
DesignThursday, March 3, 2011
DesignThursday, March 3, 2011
Publisher Code                 $channel->exchange_declare(upload-pictures, fanout, false,                 true, false);   ...
Publisher Code                 $channel->exchange_declare(upload-pictures, fanout, false,                 true, false);   ...
Publisher Code                 $channel->exchange_declare(upload-pictures, fanout, false,                 true, false);   ...
Publisher Code                 $channel->exchange_declare(upload-pictures, fanout, false,                 true, false);   ...
Publisher Code                 $channel->exchange_declare(upload-pictures, fanout, false,                 true, false);   ...
Consumer Code                 $channel->exchange_declare(upload-pictures, fanout,                             false, true,...
Consumer Code                 $channel->exchange_declare(upload-pictures, fanout,                             false, true,...
Consumer Code                 $channel->exchange_declare(upload-pictures, fanout,                             false, true,...
Consumer Code                 $channel->exchange_declare(upload-pictures, fanout,                             false, true,...
Consumer Code                 $channel->exchange_declare(upload-pictures, fanout,                             false, true,...
Consumer Code                 $channel->exchange_declare(upload-pictures, fanout,                             false, true,...
Consumer Code                 $consumer = function($msg){                      $meta = json_decode($msg->body, true);     ...
Consumer Code                 $consumer = function($msg){                      $meta = json_decode($msg->body, true);     ...
Consumer Code                 $consumer = function($msg){                      $meta = json_decode($msg->body, true);     ...
Consumer Code                 $consumer = function($msg){                      $meta = json_decode($msg->body, true);     ...
Consumer Code                 $consumer = function($msg){                      $meta = json_decode($msg->body, true);     ...
Scenario                          Distributed LoggingThursday, March 3, 2011
RequirementsThursday, March 3, 2011
Requirements                    • Several Web ServersThursday, March 3, 2011
Requirements                    • Several Web Servers                    • Logic Separated by Module/ActionThursday, March...
Requirements                    • Several Web Servers                    • Logic Separated by Module/Action               ...
Requirements                    • Several Web Servers                    • Logic Separated by Module/Action               ...
Requirements                    • Several Web Servers                    • Logic Separated by Module/Action               ...
DesignThursday, March 3, 2011
DesignThursday, March 3, 2011
DesignThursday, March 3, 2011
DesignThursday, March 3, 2011
DesignThursday, March 3, 2011
Publisher Code                 $channel->exchange_declare(logs, topic, false,                               true, false); ...
Publisher Code                 $channel->exchange_declare(logs, topic, false,                               true, false); ...
Publisher Code                 $channel->exchange_declare(logs, topic, false,                               true, false); ...
Publisher Code                 $channel->exchange_declare(logs, topic, false,                               true, false); ...
Consumer Code                           Get messages sent by host:                                   server1Thursday, Marc...
Consumer Code                 $channel->exchange_declare(logs, topic, false,                               true, false);  ...
Consumer Code                 $channel->exchange_declare(logs, topic, false,                               true, false);  ...
Consumer Code                 $channel->exchange_declare(logs, topic, false,                               true, false);  ...
Consumer Code                 $channel->exchange_declare(logs, topic, false,                               true, false);  ...
Consumer Code                           Get all error messagesThursday, March 3, 2011
Consumer Code                 $channel->exchange_declare(logs, topic, false,                               true, false);  ...
Consumer Code                 $channel->exchange_declare(logs, topic, false,                               true, false);  ...
Consumer Code                 $channel->exchange_declare(logs, topic, false,                               true, false);  ...
Consumer Code                 $channel->exchange_declare(logs, topic, false,                               true, false);  ...
Symfony IntegrationThursday, March 3, 2011
RabbitMQ BundleThursday, March 3, 2011
RabbitMQ Bundle                                  Goal:                            To be easy to useThursday, March 3, 2011
RabbitMQ Bundle                                        Publish a Message:                          $msg = array(user_id =>...
RabbitMQ Bundle                             Consume a Message:           $ ./app/console_dev rabbitmq:consumer -m 1 upload...
RabbitMQ Bundle                            Consume 50 Messages:           $ ./app/console_dev rabbitmq:consumer -m 50 uplo...
RabbitMQ Bundle                           Consume infinite* Messages:           $ ./app/console_dev rabbitmq:consumer -m -1...
RabbitMQ Bundle                                 Configuration:           # app/config/config.yml           rabbitmq.config:...
RabbitMQ Bundle                                 Configuration:           # app/config/config.yml           rabbitmq.config:...
RabbitMQ Bundle                                Configuration:           # app/config/config.yml           rabbitmq.config: ...
RabbitMQ Bundle                                    Using a Producer:           public function indexAction($name)         ...
RabbitMQ Bundle                               Consumer Class:           class UploadPictureConsumer extends ContainerAware...
RabbitMQ Bundle                                Recap:Thursday, March 3, 2011
RabbitMQ Bundle                                              Recap:                • Add an entry for the consumer/produce...
RabbitMQ Bundle                                              Recap:                • Add an entry for the consumer/produce...
RabbitMQ Bundle                                              Recap:                • Add an entry for the consumer/produce...
RabbitMQ Bundle                                              Recap:                • Add an entry for the consumer/produce...
RabbitMQ Bundle                              There’s more:Thursday, March 3, 2011
RabbitMQ Bundle                                There’s more:                • RPC clients and serversThursday, March 3, 2011
RabbitMQ Bundle                                There’s more:                • RPC clients and servers                • Ano...
RabbitMQ Bundle                                There’s more:                • RPC clients and servers                • Ano...
RabbitMQ Bundle                                           Fork it at                          http://github.com/videlalvar...
Why RabbitMQ?Thursday, March 3, 2011
RabbitMQ                    • Enterprise Messaging System                    • Open Source MPL                    • Writte...
Features                    • Reliable and High Scalable                    • Easy To install                    • Easy To...
Client Libraries                    • Java                    • .NET/C#                    • Erlang                    • R...
Docs/Support                    •     http://www.rabbitmq.com/documentation.html                    •     http://dev.rabbi...
One Setup for HAThursday, March 3, 2011
ConclusionThursday, March 3, 2011
Conclusion                    • FlexibilityThursday, March 3, 2011
Conclusion                    • Flexibility                    • ScalabilityThursday, March 3, 2011
Conclusion                    • Flexibility                    • Scalability                    • InteroperabilityThursday...
Conclusion                    • Flexibility                    • Scalability                    • Interoperability        ...
Questions?Thursday, March 3, 2011
Thanks!                                   Álvaro Videla                             http://twitter.com/old_sound          ...
Upcoming SlideShare
Loading in...5
×

Theres a rabbit on my symfony

19,271

Published on

Talk given at Symfony Live Paris 2011 http://www.symfony-live.com/paris/schedule#session-av1

Published in: Technology
1 Comment
35 Likes
Statistics
Notes
  • Very nice and detailed discussion - many thanks Alvaro for sharing your knowledge.

    Best wishes,

    Atish
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
19,271
On Slideshare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
206
Comments
1
Likes
35
Embeds 0
No embeds

No notes for slide

Theres a rabbit on my symfony

  1. 1. Theres a Rabbit on my Symfony RabbitMQ and Symfony2 Integration Álvaro Videla Symfony Live 2011Thursday, March 3, 2011
  2. 2. Who?Thursday, March 3, 2011
  3. 3. About Me • Development Manager at TheNetCircle.com • Blog: http://videlalvaro.github.com/ • Twitter: @old_soundThursday, March 3, 2011
  4. 4. About Me • Developer at Liip • Blog: http://videlalvaro.github.com/ • Twitter: @old_soundThursday, March 3, 2011
  5. 5. About Me Co-authoring RabbitMQ in Action http://bit.ly/rabbitmqThursday, March 3, 2011
  6. 6. Why Do I need RabbitMQ?Thursday, March 3, 2011
  7. 7. OrThursday, March 3, 2011
  8. 8. Why Do I need Messaging?Thursday, March 3, 2011
  9. 9. An Upload Picture Form as seen by:Thursday, March 3, 2011
  10. 10. The UserThursday, March 3, 2011
  11. 11. I don’t want to wait till your app resizes my image!Thursday, March 3, 2011
  12. 12. The Product OwnerThursday, March 3, 2011
  13. 13. Can we also notify the user friends when she uploads a new image?Thursday, March 3, 2011
  14. 14. Can we also notify the user friends when she uploads a new image? I forgot to mention we need it for tomorrow…Thursday, March 3, 2011
  15. 15. The SysadminThursday, March 3, 2011
  16. 16. Dumb! You’re delivering full size images! The bandwidth bill has tripled!Thursday, March 3, 2011
  17. 17. Dumb! You’re delivering full size images! The bandwidth bill has tripled! We need this fixed for yesterday!Thursday, March 3, 2011
  18. 18. The Developer in the other teamThursday, March 3, 2011
  19. 19. I need to call your PHP stuff but from PythonThursday, March 3, 2011
  20. 20. I need to call your PHP stuff but from Python And also Java starting next weekThursday, March 3, 2011
  21. 21. YouThursday, March 3, 2011
  22. 22. FML!Thursday, March 3, 2011
  23. 23. Is there a solution?Thursday, March 3, 2011
  24. 24. RabbitMQ & AMQPThursday, March 3, 2011
  25. 25. AMQPThursday, March 3, 2011
  26. 26. AMQP • Advanced Message Queuing Protocol • Suits Interoperability • Completely Open Protocol • Binary Protocol • AMQP Model • AMQP Wire FormatThursday, March 3, 2011
  27. 27. AMQP Model • Exchanges • Message Queues • Bindings • Rules for binding themThursday, March 3, 2011
  28. 28. AMQP Wire Protocol • Functional Layer • Transport LayerThursday, March 3, 2011
  29. 29. Message Flow http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/chap-Messaging_Tutorial-Initial_Concepts.htmlThursday, March 3, 2011
  30. 30. Exchange Types • Fanout • Direct • TopicThursday, March 3, 2011
  31. 31. http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concepts- Fanout_Exchange.htmlThursday, March 3, 2011
  32. 32. http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concepts- Direct_Exchange.htmlThursday, March 3, 2011
  33. 33. http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concepts- Topic_Exchange.htmlThursday, March 3, 2011
  34. 34. Usage ScenariosThursday, March 3, 2011
  35. 35. Usage Scenarios • Batch ProcessingThursday, March 3, 2011
  36. 36. Usage Scenarios • Batch Processing • Image UploadingThursday, March 3, 2011
  37. 37. Usage Scenarios • Batch Processing • Image Uploading • Distributed LoggingThursday, March 3, 2011
  38. 38. Scenario Batch ProcessingThursday, March 3, 2011
  39. 39. RequirementsThursday, March 3, 2011
  40. 40. Requirements • Generate XMLThursday, March 3, 2011
  41. 41. Requirements • Generate XML • Distribution Over a ClusterThursday, March 3, 2011
  42. 42. Requirements • Generate XML • Distribution Over a Cluster • Elasticity - Add/Remove new workersThursday, March 3, 2011
  43. 43. Requirements • Generate XML • Distribution Over a Cluster • Elasticity - Add/Remove new workers • No Code ChangesThursday, March 3, 2011
  44. 44. DesignThursday, March 3, 2011
  45. 45. 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, March 3, 2011
  46. 46. 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, March 3, 2011
  47. 47. 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, March 3, 2011
  48. 48. 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, March 3, 2011
  49. 49. 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, March 3, 2011
  50. 50. 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, March 3, 2011
  51. 51. 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, March 3, 2011
  52. 52. 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, March 3, 2011
  53. 53. 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, March 3, 2011
  54. 54. 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, March 3, 2011
  55. 55. 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, March 3, 2011
  56. 56. 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, March 3, 2011
  57. 57. 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, March 3, 2011
  58. 58. Scenario Upload PicturesThursday, March 3, 2011
  59. 59. RequirementsThursday, March 3, 2011
  60. 60. Requirements • Upload PictureThursday, March 3, 2011
  61. 61. Requirements • Upload Picture • Reward UserThursday, March 3, 2011
  62. 62. Requirements • Upload Picture • Reward User • Notify User FriendsThursday, March 3, 2011
  63. 63. Requirements • Upload Picture • Reward User • Notify User Friends • Resize PictureThursday, March 3, 2011
  64. 64. Requirements • Upload Picture • Reward User • Notify User Friends • Resize Picture • No Code ChangesThursday, March 3, 2011
  65. 65. DesignThursday, March 3, 2011
  66. 66. DesignThursday, March 3, 2011
  67. 67. DesignThursday, March 3, 2011
  68. 68. Publisher Code $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);Thursday, March 3, 2011
  69. 69. Publisher Code $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);Thursday, March 3, 2011
  70. 70. Publisher Code $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);Thursday, March 3, 2011
  71. 71. Publisher Code $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);Thursday, March 3, 2011
  72. 72. Publisher Code $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);Thursday, March 3, 2011
  73. 73. 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, March 3, 2011
  74. 74. 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, March 3, 2011
  75. 75. 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, March 3, 2011
  76. 76. 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, March 3, 2011
  77. 77. 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, March 3, 2011
  78. 78. 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, March 3, 2011
  79. 79. 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]); };Thursday, March 3, 2011
  80. 80. 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]); };Thursday, March 3, 2011
  81. 81. 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]); };Thursday, March 3, 2011
  82. 82. 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]); };Thursday, March 3, 2011
  83. 83. 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]); };Thursday, March 3, 2011
  84. 84. Scenario Distributed LoggingThursday, March 3, 2011
  85. 85. RequirementsThursday, March 3, 2011
  86. 86. Requirements • Several Web ServersThursday, March 3, 2011
  87. 87. Requirements • Several Web Servers • Logic Separated by Module/ActionThursday, March 3, 2011
  88. 88. Requirements • Several Web Servers • Logic Separated by Module/Action • Several Log Levels:Thursday, March 3, 2011
  89. 89. Requirements • Several Web Servers • Logic Separated by Module/Action • Several Log Levels: • Info, Warning, ErrorThursday, March 3, 2011
  90. 90. Requirements • Several Web Servers • Logic Separated by Module/Action • Several Log Levels: • Info, Warning, Error • Add/Remove log listeners at willThursday, March 3, 2011
  91. 91. DesignThursday, March 3, 2011
  92. 92. DesignThursday, March 3, 2011
  93. 93. DesignThursday, March 3, 2011
  94. 94. DesignThursday, March 3, 2011
  95. 95. DesignThursday, March 3, 2011
  96. 96. Publisher Code $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);Thursday, March 3, 2011
  97. 97. Publisher Code $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);Thursday, March 3, 2011
  98. 98. Publisher Code $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);Thursday, March 3, 2011
  99. 99. Publisher Code $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);Thursday, March 3, 2011
  100. 100. Consumer Code Get messages sent by host: server1Thursday, March 3, 2011
  101. 101. Consumer Code $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, March 3, 2011
  102. 102. Consumer Code $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, March 3, 2011
  103. 103. Consumer Code $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, March 3, 2011
  104. 104. Consumer Code $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, March 3, 2011
  105. 105. Consumer Code Get all error messagesThursday, March 3, 2011
  106. 106. Consumer Code $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, March 3, 2011
  107. 107. Consumer Code $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, March 3, 2011
  108. 108. Consumer Code $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, March 3, 2011
  109. 109. Consumer Code $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, March 3, 2011
  110. 110. Symfony IntegrationThursday, March 3, 2011
  111. 111. RabbitMQ BundleThursday, March 3, 2011
  112. 112. RabbitMQ Bundle Goal: To be easy to useThursday, March 3, 2011
  113. 113. RabbitMQ Bundle Publish a Message: $msg = array(user_id => 1235, image_path => /path/to/new/ pic.png); $this->get(rabbitmq.upload_picture_producer)-> publish(serialize($msg));Thursday, March 3, 2011
  114. 114. RabbitMQ Bundle Consume a Message: $ ./app/console_dev rabbitmq:consumer -m 1 upload_pictureThursday, March 3, 2011
  115. 115. RabbitMQ Bundle Consume 50 Messages: $ ./app/console_dev rabbitmq:consumer -m 50 upload_pictureThursday, March 3, 2011
  116. 116. RabbitMQ Bundle Consume infinite* Messages: $ ./app/console_dev rabbitmq:consumer -m -1 upload_picture *messages may not be infiniteThursday, March 3, 2011
  117. 117. RabbitMQ Bundle Configuration: # app/config/config.yml rabbitmq.config: connections: default: host: localhost port: 5672 user: guest password: guest vhost: /Thursday, March 3, 2011
  118. 118. RabbitMQ Bundle Configuration: # app/config/config.yml rabbitmq.config: connections: ... producers: upload_picture: connection: default exchange_options: {name: upload-picture, type: direct}Thursday, March 3, 2011
  119. 119. RabbitMQ Bundle Configuration: # app/config/config.yml rabbitmq.config: connections: ... consumers: upload_picture: connection: default exchange_options: {name: upload-picture, type: direct} queue_options: {name: upload-picture} callback: upload_picture_serviceThursday, March 3, 2011
  120. 120. RabbitMQ Bundle Using a Producer: public function indexAction($name) { ... $msg = array(user_id => 1235, image_path => /path/to/new/pic.png); $this->get(rabbitmq.upload_picture_producer)-> publish(serialize($msg)); ... }Thursday, March 3, 2011
  121. 121. RabbitMQ Bundle Consumer Class: class UploadPictureConsumer extends ContainerAware implements ConsumerInterface { public function execute($msg) { // Process picture upload. // $msg will be what was published // from the Controller. } }Thursday, March 3, 2011
  122. 122. RabbitMQ Bundle Recap:Thursday, March 3, 2011
  123. 123. RabbitMQ Bundle Recap: • Add an entry for the consumer/producer in the configuration.Thursday, March 3, 2011
  124. 124. RabbitMQ Bundle Recap: • Add an entry for the consumer/producer in the configuration. • Implement your Callback.Thursday, March 3, 2011
  125. 125. RabbitMQ Bundle Recap: • Add an entry for the consumer/producer in the configuration. • Implement your Callback. • Start the consumer from the CLI.Thursday, March 3, 2011
  126. 126. RabbitMQ Bundle Recap: • Add an entry for the consumer/producer in the configuration. • Implement your Callback. • Start the consumer from the CLI. • Add code to publish messages.Thursday, March 3, 2011
  127. 127. RabbitMQ Bundle There’s more:Thursday, March 3, 2011
  128. 128. RabbitMQ Bundle There’s more: • RPC clients and serversThursday, March 3, 2011
  129. 129. RabbitMQ Bundle There’s more: • RPC clients and servers • Anonymous consumersThursday, March 3, 2011
  130. 130. RabbitMQ Bundle There’s more: • RPC clients and servers • Anonymous consumers • Parallel RPCThursday, March 3, 2011
  131. 131. RabbitMQ Bundle Fork it at http://github.com/videlalvaro/RabbitMqBundleThursday, March 3, 2011
  132. 132. Why RabbitMQ?Thursday, March 3, 2011
  133. 133. RabbitMQ • Enterprise Messaging System • Open Source MPL • Written in Erlang/OTP • Commercial SupportThursday, March 3, 2011
  134. 134. Features • Reliable and High Scalable • Easy To install • Easy To Cluster • Runs on: Windows, Solaris, Linux, OSX • AMQP 0.8 - 0.9.1Thursday, March 3, 2011
  135. 135. Client Libraries • Java • .NET/C# • Erlang • Ruby, Python, PHP, Perl, AS3, Lisp, Scala, Clojure, HaskellThursday, March 3, 2011
  136. 136. Docs/Support • http://www.rabbitmq.com/documentation.html • http://dev.rabbitmq.com/wiki/ • #rabbitmq at irc.freenode.net • http://www.rabbitmq.com/email-archive.htmlThursday, March 3, 2011
  137. 137. One Setup for HAThursday, March 3, 2011
  138. 138. ConclusionThursday, March 3, 2011
  139. 139. Conclusion • FlexibilityThursday, March 3, 2011
  140. 140. Conclusion • Flexibility • ScalabilityThursday, March 3, 2011
  141. 141. Conclusion • Flexibility • Scalability • InteroperabilityThursday, March 3, 2011
  142. 142. Conclusion • Flexibility • Scalability • Interoperability • Reduce OpsThursday, March 3, 2011
  143. 143. Questions?Thursday, March 3, 2011
  144. 144. Thanks! Álvaro Videla http://twitter.com/old_sound http://github.com/videlalvaro http://github.com/tnc http://www.slideshare.net/old_soundThursday, March 3, 2011
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×