Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Introducing Practical RabbitMQ (php[tek] 2016 - Tutorial)

584 views

Published on

In this tutorial, I will introduce RabbitMQ as a solution to scalable, interoperable, flexible applications. This tutorial is perfect for those who want to dive deep into RabbitMQ with little or no pre-existing knowledge about message queuing systems. Once you have finished the tutorial, you will know how to set up basic publish/subscribe message queues, control the flow of messages using various exchanges, and understand various features of RabbitMQ, such as RPC, TTL, and DLX.

Published in: Technology
  • Be the first to comment

Introducing Practical RabbitMQ (php[tek] 2016 - Tutorial)

  1. 1. this slide is intentionally left blank
  2. 2. Before we begin... Copy folder from USB to your local machine. $ cd /path/to/the/folder/you/copied/from/usb/ $ vagrant box add asgrim/rmq-vm rmq-vm.box $ vagrant up --no-provision Test it in your browser... http://192.168.33.99:15672/ @asgrim
  3. 3. Introducing Practical RabbitMQ James Titcumb @asgrim
  4. 4. James Titcumb www.jamestitcumb.com www.roave.com www.phphants.co.uk www.phpsouthcoast.co.uk @asgrim Who is this guy?
  5. 5. What is a message? @asgrim
  6. 6. What is message queueing? @asgrim
  7. 7. Photo: http://spitalfieldslife.com/2011/08/27/a-fox-in-hoxton-2/
  8. 8. Separation of Concerns @asgrim
  9. 9. Scaling with Rabbit RabbitMQApplication Background processing @asgrim
  10. 10. Scaling with Rabbit RabbitMQApplication Background processing Background processing @asgrim
  11. 11. Scaling with Rabbit RabbitMQApplication Background processing Background processing Background processing @asgrim
  12. 12. Scaling with Rabbit RabbitMQApplication Background processing Background processing Background processing Background processing @asgrim
  13. 13. Scaling with Rabbit RabbitMQApplication Background processing Background processing Background processing Background processing Background processing @asgrim
  14. 14. Real world uses? @asgrim
  15. 15. SOA @asgrim
  16. 16. Why RabbitMQ? @asgrim
  17. 17. (you need Vagrant+VirtualBox already) Installing RabbitMQ @asgrim
  18. 18. vagrant up Copy folder from USB to your local machine. $ cd /path/to/the/folder/you/copied/from/usb/ $ vagrant box add asgrim/rmq-vm rmq-vm.box $ vagrant up --no-provision Test it in your browser... http://192.168.33.99:15672/ @asgrim
  19. 19. Library with Composer composer require videlalvaro/php-amqplib @asgrim
  20. 20. The Management Console http://192.168.33.99:15672/ @asgrim
  21. 21. Practical @asgrim
  22. 22. Objective: Basic Queuing Producer Consumer test_queue 1 2 3 4 5 @asgrim
  23. 23. Exchanges: Fanout @asgrim
  24. 24. Objective: Fanout Exchange test_exchange amq.KfgPZ3PE amq.cK5Cp3FC Consumer Consumer Producer 1 1 2 2 3 3 4 4 5 5 @asgrim
  25. 25. A word on Temporary Queues test_exchangeProducer Messages go nowhere @asgrim
  26. 26. Exchanges: Direct @asgrim
  27. 27. Objective: Direct Exchange test_direct BK = apple BK = banana, apple Consumer Consumer Producer BK = orange, banana, apple Consumer @asgrim
  28. 28. Objective: Direct Exchange test_direct BK = apple BK = banana, apple Consumer Consumer Producer MESSAGE ROUTING KEY = ORANGE BK = orange, banana, apple Consumer @asgrim
  29. 29. Objective: Direct Exchange test_direct BK = apple BK = banana, apple Consumer Consumer Producer MESSAGE ROUTING KEY = BANANA BK = orange, banana, apple Consumer @asgrim
  30. 30. Objective: Direct Exchange test_direct BK = apple BK = banana, apple Consumer Consumer Producer MESSAGE ROUTING KEY = APPLE BK = orange, banana, apple Consumer @asgrim
  31. 31. Exchanges: Topic @asgrim
  32. 32. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer BK = green.# Consumer BK = *.grass.* / *.*.long Consumer @asgrim
  33. 33. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer RED.VEGETABLE BK = green.# Consumer BK = *.grass.* / *.*.long Consumer @asgrim
  34. 34. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer GREEN.VEGETABLE BK = green.# Consumer BK = *.grass.* / *.*.long Consumer @asgrim
  35. 35. Objective: Topic Exchange test_topic BK = *.vegetable BK = # Consumer Consumer Producer GREEN.GRASS.LONG BK = green.# Consumer BK = *.grass.* / *.*.long Consumer @asgrim
  36. 36. Message Acknowledgement @asgrim
  37. 37. Real World Example @asgrim
  38. 38. Fetch message Logging Sequence ApplicationBrowser Log Server HTTP request JSON via AMQP Error! HTTP response RabbitMQ @asgrim
  39. 39. Flexibility! @asgrim
  40. 40. Parallel Processing @asgrim
  41. 41. test_exchange amq.KfgPZ3PE amq.cK5Cp3FC Consumer Producer 1 1 2 2 3 3 4 4 5 5 Consumer Consumer Consumer Consumer Consumer Consumer Consumer Parallel Processing @asgrim
  42. 42. Photo: © Rob Allen (akrabat) https://flic.kr/p/6wp9iz @asgrim
  43. 43. RPC @asgrim
  44. 44. RPC example Producer Consumer test_queue 1 reply_to: amq.gen-Xa2 1’ @asgrim
  45. 45. TTL @asgrim
  46. 46. TTL - per queue message Producer Consumer test_queue 1 2 3 4 5 } 10s@asgrim
  47. 47. TTL - per message Producer Consumer test_queue 1 2 3 4 5 5s 3s 7s 1s 9s@asgrim
  48. 48. TTL - queue Producer test_queue } 5s (if no consumers) @asgrim
  49. 49. DLX @asgrim
  50. 50. DLX test_exchange amq.KfgPZ3PE Producer 1 dlx_exchange dlx_queue 1 @asgrim
  51. 51. Scheduling / Delayed messages @asgrim
  52. 52. Shovel @asgrim
  53. 53. Priority @asgrim
  54. 54. Management HTTP API @asgrim
  55. 55. Infrastructure @asgrim
  56. 56. Problem: SPOF @asgrim
  57. 57. Solution 1: Clustering @asgrim
  58. 58. Clustering RabbitMQ Node 1 RabbitMQ Node 3 RabbitMQ Node 2 RabbitMQ Node 4 RabbitMQ Node 5 RabbitMQ Node 6 Load Balance / Floating IP / Low TTL DNS etc. @asgrim
  59. 59. Everything Replicates (except queues…) @asgrim
  60. 60. Disk / RAM @asgrim
  61. 61. Configuration... @asgrim
  62. 62. /etc/rabbitmq/rabbitmq.config [ {rabbit, [ {loopback_users, []}, {vm_memory_high_watermark, 0.8} ]} ]. @asgrim
  63. 63. /etc/rabbitmq/rabbitmq.config [{{{[{{[{{}}{][[[{[{{}[[}{[[{}[][}{}}}{}}{{,},]{ [[{rabbit, [{{}[[}{,,{}[][}{[][][{}{{{{}}}}[[}{{ {{}}{loopback_users, []},[][][]{}{}{}<}{[}[][][} [{{[{vm_memory_high_watermark, 0.8}]]{}{[[[]]{}] {{]}[{[{{}[[}{]]{}[][,{}[][}{[][][{}.[]}{]][][]} ]...{}[][,]{.}[][}{}[[[{}{][]}{}{}[}{}{}{]{}{}}[ @asgrim
  64. 64. node1$ rabbitmqctl cluster_status Cluster status of node rabbit@node1 ... [{nodes,[{disc,[rabbit@node1]}]},{running_nodes,[rabbit@node1]}] ...done. Creating a cluster @asgrim
  65. 65. node2$ rabbitmqctl join_cluster --ram rabbit@node1 node3$ rabbitmqctl join_cluster rabbit@node2 node3$ rabbitmqctl cluster_status Cluster status of node rabbit@node3 ... [{nodes,[{disc,[rabbit@node3,rabbit@node1]},{ram,[rabbit@node2]}]}, {running_nodes,[rabbit@node2,rabbit@node1,rabbit@node3]}] ...done. Creating a cluster @asgrim
  66. 66. Starting/Stopping Nodes @asgrim
  67. 67. node1$ rabbitmqctl stop_app node2$ rabbitmqctl forget_cluster_node rabbit@node1 node1$ rabbitmqctl reset node1$ rabbitmqctl start_app node2$ rabbitmqctl cluster_status Cluster status of node rabbit@node2 ... [{nodes,[{disc,[rabbit@node3]},{ram,[rabbit@node2]}]}, {running_nodes,[rabbit@node2,rabbit@node3]}] ...done. Removing Nodes @asgrim
  68. 68. Solution 2: HA @asgrim
  69. 69. HA + Queue Mirroring RabbitMQ Node 1 RabbitMQ Node 2 Load Balance / Floating IP / Low TTL DNS etc. @asgrim
  70. 70. One more thing... @asgrim
  71. 71. Challenge! @asgrim
  72. 72. Any questions? :) https://joind.in/talk/8a46c James Titcumb @asgrim

×