SlideShare a Scribd company logo
RabbitMQ
AMQP in PHP
Blaž Strmole, Bled, 12. 2. 2015
RabbitMQ
● Message broker
● AMQP in še več
● Napisan v Erlang-u
● Open source
AMQP
● Advanced Message Queuing Protocol
● AMQP is a networking protocol that enables
conforming client applications to
communicate with conforming messaging
middleware brokers.
AMQP - zgodovina
● Zasnovan 2003
● Najprej ga uporabljajo v finančnih aplikacijah
● Nov 2008 izdajo verzijo 0.9.1
● Nov 2011 izdajo verzijo 1.0
● Okt 2012 potrjen kot OASIS standard
● RabbitMQ uporablja 0.9.1
AMQP - model
● Publisher pošlje sporočilo v Exchange
(mailbox).
● Glede na routing se sporočilo distribuira v
Queues.
● Broker ga posreduje Consumer-ju ali pa ga
consumer sam potegne iz queue.
● RabbitMq == Exchange + Queues + Broker
AMQP - Exchange
● Sporočila so poslana sem.
● Vedno obstaja privzet Exchange
● Tu se izvaja routing.
AMQP - direct routing
● Sporočila gredo v določeno vrsto.
● Uporabno za workerje (gearman).
Publisher Queue Consumer
AMQP - fanout routing
● Vsako sporočilo gre v več vrst.
● Naredi se kopija sporočila za vsako vrsto.
Publisher Queue2 Consumer2
Consumer1
Consumer3
AMQP - topic routing
● Sporočilo gre v eno ali več vrst.
● Kam gre se določi glede na routing key od
sporočila.
● Pravila se določijo v Exchange.
AMQP - header routing
● Sporočilo gre v eno vrsto.
● Kam gre se določi s header atributi.
● Podpira any ali all.
● Direct routing on steroids.
AMQP - queues
● Jih je potrebno predhodno določiti (declare).
● Imajo več lastnosti:
– Ime
– Persistenco (durable)
– Exclusive
– Auto-delete
– Argumente
AMQP - consumers
● Push
● Pull
● Lahko več na eno vrsto
● Exclusive consumer
● Potrditev prejema sporočila
(acknowledgement)
● Zavrnitev sporočila
AMQP - connections
● TCP
● Uporabljajo avtentikacijo
● Lahko tudi TLS (SSL)
● Jih je potrrebno zaključevati (close)
RabbitMQ - PHP
● Php-amqplib
– Spisana v PHP (5.3)
– Avtor: Alvaro Videla
– Podpira vse kar RabbitMQ
● Pecl AMQP lib
– Bazira na RabbitMQ C AMQP client lib
RabbitMQ – Primer publisher
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();
RabbitMQ – Primer consumer
use PhpAmqpLibConnectionAMQPConnection;
$connection = new AMQPConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
$channel->queue_declare('hello', false, false, false, false);
$callback = function($msg) {
echo " [x] Received ", $msg->body, "n";
};
$channel->basic_consume('hello', '', false, true, false, false, $callback);
echo ' [*] Waiting for messages. To exit press CTRL+C', "n";
while(count($channel->callbacks)) {
$channel->wait();
}
$channel->close();
$connection->close();
Vprašanja?
RabbitMQ, AMQP in PHP

More Related Content

PDF
XMPP & AMQP
PPTX
The RabbitMQ Message Broker
PDF
Messaging with RabbitMQ and AMQP
PDF
Introduction to AMQP Messaging with RabbitMQ
PPTX
Message Broker System and RabbitMQ
PPTX
Spring RabbitMQ
PDF
The Future of Messaging: RabbitMQ and AMQP
PDF
An update from the RabbitMQ team - Michael Klishin
XMPP & AMQP
The RabbitMQ Message Broker
Messaging with RabbitMQ and AMQP
Introduction to AMQP Messaging with RabbitMQ
Message Broker System and RabbitMQ
Spring RabbitMQ
The Future of Messaging: RabbitMQ and AMQP
An update from the RabbitMQ team - Michael Klishin

What's hot (20)

PDF
Messaging Standards and Systems - AMQP & RabbitMQ
PDF
Distributed messaging with AMQP
PDF
What we've learned from running thousands of production RabbitMQ clusters - L...
KEY
RabbitMQ And Nanite
ODP
Introduction To RabbitMQ
PDF
Messaging with amqp and rabbitmq
PPTX
What is RabbitMQ ?
PPT
Easy enterprise application integration with RabbitMQ and AMQP
PDF
NullMQ @ PDX
PPT
Amqp Basic
PDF
A Closer Look at RabbitMQ
PDF
Messaging Standards and Systems - AMQP & RabbitMQ
PDF
[@NaukriEngineering] Messaging Queues
PDF
ZeroMQ with NodeJS
PDF
Messaging in the Cloud - AMQP, RabbitMQ and Spring
PDF
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
PDF
Rabbitmq, amqp Intro - Messaging Patterns
PDF
Think beyond http
PPTX
Build reliable, traceable, distributed systems with ZeroMQ
PPT
Leveraging zeromq for node.js
Messaging Standards and Systems - AMQP & RabbitMQ
Distributed messaging with AMQP
What we've learned from running thousands of production RabbitMQ clusters - L...
RabbitMQ And Nanite
Introduction To RabbitMQ
Messaging with amqp and rabbitmq
What is RabbitMQ ?
Easy enterprise application integration with RabbitMQ and AMQP
NullMQ @ PDX
Amqp Basic
A Closer Look at RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQ
[@NaukriEngineering] Messaging Queues
ZeroMQ with NodeJS
Messaging in the Cloud - AMQP, RabbitMQ and Spring
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Rabbitmq, amqp Intro - Messaging Patterns
Think beyond http
Build reliable, traceable, distributed systems with ZeroMQ
Leveraging zeromq for node.js
Ad

Similar to Rabbit mq, amqp and php (20)

PDF
quickguide-einnovator-3-rabbitmq
PDF
Integrating PostgreSql with RabbitMQ
ZIP
XMPP & AMQP in Ruby
PDF
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
PPTX
Spring RabbitMQ
PPTX
RabbitMQ and AMQP Model
PDF
AMQP with RabbitMQ
PPTX
Rabbit MQ
PPTX
Commication Framework in OpenStack
PDF
PostgreSQL: meet your queue
PDF
Построение распределенной системы сбора данных с помощью RabbitMQ, Alvaro Vid...
PDF
IBM MQ Clustering (2017 version)
PPTX
zeromq
PPTX
RabbitMQ interview Questions and Answers
PDF
Messaging for Modern Applications
PDF
Russell spring one2gx_messaging_india
PDF
Introducing Kafka-on-Pulsar: bring native Kafka protocol support to Apache Pu...
PDF
Follow the White Rabbit - Message Queues with PHP
PDF
JDD 2017: Brace yourself! Storm is coming! (Łukasz Gebel, Michał Koziorowski)
quickguide-einnovator-3-rabbitmq
Integrating PostgreSql with RabbitMQ
XMPP & AMQP in Ruby
Message Queuing - Gearman, Mosquitto, Kafka and RabbitMQ
Spring RabbitMQ
RabbitMQ and AMQP Model
AMQP with RabbitMQ
Rabbit MQ
Commication Framework in OpenStack
PostgreSQL: meet your queue
Построение распределенной системы сбора данных с помощью RabbitMQ, Alvaro Vid...
IBM MQ Clustering (2017 version)
zeromq
RabbitMQ interview Questions and Answers
Messaging for Modern Applications
Russell spring one2gx_messaging_india
Introducing Kafka-on-Pulsar: bring native Kafka protocol support to Apache Pu...
Follow the White Rabbit - Message Queues with PHP
JDD 2017: Brace yourself! Storm is coming! (Łukasz Gebel, Michał Koziorowski)
Ad

Recently uploaded (20)

PDF
System and Network Administraation Chapter 3
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
history of c programming in notes for students .pptx
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
Introduction to Artificial Intelligence
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
AI in Product Development-omnex systems
System and Network Administraation Chapter 3
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
How Creative Agencies Leverage Project Management Software.pdf
history of c programming in notes for students .pptx
Understanding Forklifts - TECH EHS Solution
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
How to Migrate SBCGlobal Email to Yahoo Easily
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Odoo POS Development Services by CandidRoot Solutions
PTS Company Brochure 2025 (1).pdf.......
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Softaken Excel to vCard Converter Software.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
CHAPTER 2 - PM Management and IT Context
Introduction to Artificial Intelligence
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development
AI in Product Development-omnex systems

Rabbit mq, amqp and php

  • 1. RabbitMQ AMQP in PHP Blaž Strmole, Bled, 12. 2. 2015
  • 2. RabbitMQ ● Message broker ● AMQP in še več ● Napisan v Erlang-u ● Open source
  • 3. AMQP ● Advanced Message Queuing Protocol ● AMQP is a networking protocol that enables conforming client applications to communicate with conforming messaging middleware brokers.
  • 4. AMQP - zgodovina ● Zasnovan 2003 ● Najprej ga uporabljajo v finančnih aplikacijah ● Nov 2008 izdajo verzijo 0.9.1 ● Nov 2011 izdajo verzijo 1.0 ● Okt 2012 potrjen kot OASIS standard ● RabbitMQ uporablja 0.9.1
  • 5. AMQP - model ● Publisher pošlje sporočilo v Exchange (mailbox). ● Glede na routing se sporočilo distribuira v Queues. ● Broker ga posreduje Consumer-ju ali pa ga consumer sam potegne iz queue. ● RabbitMq == Exchange + Queues + Broker
  • 6. AMQP - Exchange ● Sporočila so poslana sem. ● Vedno obstaja privzet Exchange ● Tu se izvaja routing.
  • 7. AMQP - direct routing ● Sporočila gredo v določeno vrsto. ● Uporabno za workerje (gearman). Publisher Queue Consumer
  • 8. AMQP - fanout routing ● Vsako sporočilo gre v več vrst. ● Naredi se kopija sporočila za vsako vrsto. Publisher Queue2 Consumer2 Consumer1 Consumer3
  • 9. AMQP - topic routing ● Sporočilo gre v eno ali več vrst. ● Kam gre se določi glede na routing key od sporočila. ● Pravila se določijo v Exchange.
  • 10. AMQP - header routing ● Sporočilo gre v eno vrsto. ● Kam gre se določi s header atributi. ● Podpira any ali all. ● Direct routing on steroids.
  • 11. AMQP - queues ● Jih je potrebno predhodno določiti (declare). ● Imajo več lastnosti: – Ime – Persistenco (durable) – Exclusive – Auto-delete – Argumente
  • 12. AMQP - consumers ● Push ● Pull ● Lahko več na eno vrsto ● Exclusive consumer ● Potrditev prejema sporočila (acknowledgement) ● Zavrnitev sporočila
  • 13. AMQP - connections ● TCP ● Uporabljajo avtentikacijo ● Lahko tudi TLS (SSL) ● Jih je potrrebno zaključevati (close)
  • 14. RabbitMQ - PHP ● Php-amqplib – Spisana v PHP (5.3) – Avtor: Alvaro Videla – Podpira vse kar RabbitMQ ● Pecl AMQP lib – Bazira na RabbitMQ C AMQP client lib
  • 15. RabbitMQ – Primer publisher 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();
  • 16. RabbitMQ – Primer consumer use PhpAmqpLibConnectionAMQPConnection; $connection = new AMQPConnection('localhost', 5672, 'guest', 'guest'); $channel = $connection->channel(); $channel->queue_declare('hello', false, false, false, false); $callback = function($msg) { echo " [x] Received ", $msg->body, "n"; }; $channel->basic_consume('hello', '', false, true, false, false, $callback); echo ' [*] Waiting for messages. To exit press CTRL+C', "n"; while(count($channel->callbacks)) { $channel->wait(); } $channel->close(); $connection->close();

Editor's Notes

  • #3: message-oriented middleware exchange server Publisher (vaš program) → rabbitMQ (server) → consumer (worker) cluster Amqp = Advanced Message Queuing Protocol Več kasneje... Erlang – razvil ericsson, 1986 od 1998 open source
  • #5: Organization for the Advancement of Structured Information Standards 0.9 to 1.0 totalna razlika, ni več celotna infrastruktura ampak samo še protokola za izmenjavo sporočil Nista kompatibilna v nobeno smer
  • #6: Vsak node je lahko na svoji mašini Celoten protokol je programabilen
  • #7: Exchange ima IME, persistance (ali preživi restart), auto delete (se pobriše, ko so vsi queue izprazneni), itd. Privzet Default exchange - noname - navidezno se poveže na vse queue, po imenu Štirje tipi routinga: - direct - fan out - topic - headers
  • #8: Queue ima lahko več consumerjev. Sporočilo prejme samo eden (tisti, ki je na razpolago)
  • #9: Broadcast Group chat
  • #10: Primeri uporabe - geolocation distibucija - os specifični workerji - workerji :)
  • #11: Tako kot http message ima tudi amqp message header Lahko več atributov In / ali X-match atribut to določa Ignorira routing key, prioriteta pred vsem drugim
  • #12: Ime 255 bytov utf8 Lahko se generira avtomatsko Amq na začetku je prepovedan, rezervirano Durable Durable so zapisane na disk Preživijo restart Exclusive Uporabne samo z eno povezavo Se uničijo če se uniči povezava Auto delete Se pobrišejo, ko se odjavi zadnji consumer Argumenti, za dodatne funkcionalnosti ala TTL - določeni Content type, encoding, routing key, priority,...
  • #13: exclusive consumer Noben drug ne more jemati iz vrste dokler to dela on Potrditev - ko se pošlje consumerju, auto ack - consumer mora potrditi prejem/obdelavo - sporočilo ostane dokler ni potrjeno Zavrnitev - reject → discard or requeue
  • #14: Avtentikacija user + pass
  • #15: Alvaro Videla – tudi razvijalec pri rabbitMQ Takoj kot je kaj novega je tudi tu (extensions, plugini) Relativno počasna za povezavo uporablja stream_socket_client Pecl hitra, izkušnje Obe sta amqp knjižnjice in se lahko uporabljata z katerimkoli sistemov ki pozna amqp 9.1 StormMQ, Apache Qpid,
  • #16: queue_declare Ime, passive, durable, exclusive, auto-delete Passive = false, jo naredi če je še ni Passive = true, se samo proba povezati nanjo, če je ni dobimo error (exception)
  • #17: queue_declare Ime, passive, durable, exclusive, auto-delete basic_consume Queue ime, hello consumer tag, prazno, unikatno ime consumerja če je prazno se generira avtomatsko, no_local, false (true consumer in publisher morata imeti ločen connection) no_ack, true → auto ack Exclusive, false (samo ta consumer?) no_wait, false, ali naj consumer čaka na odgovor z serverja callback