Queues and Messaging
What's it and how to use it?
Marcela Godoy
DarkmiraTour 2019
Marcela Godoy
Full-Stack Developer @ AGV Logistic
PHPSP Campinas member
PHPWomen Evangelist
❤️📖☕
@magodoy88
Communication
We need to communicate to survive
Recipient
Sender
Message
-
Confirm
arrival; -
Unique response;
-
Multiple responses.
Human model of communication is very similar with applications communication that we create
Client
Server
Request
Response
Communications evolve...
Applications too...
"Synchronous and Asynchronous are terms referring to the flux of an application"
Synchronous
Buy a
ticket
Send confirmation
Process
payment
Send a
ticket
Asynchronous
Buy a
ticket
Send
confirmation
Process
payment
Send a
ticket
Publisher
Message Broker
Consumer
A new way of communicating...
(sender)
(recipient)
But... why?
Facilitated communication between services and microservices
Performance improvement with asynchronous process
Scalability and decoupling in a easy way
What does it feed?
Message Broker
What is it?
Where it lives?
Open Source
AMQP
Advanced Message Queuing Protocol
Interoperability between services
Sets message patterns
Broker
Exchange
Virtual Host
Queue
Binding
Channel
Consumer
Publisher
Full Cycle of Message
Talking
about
this
RabbitMQ
Open Source
Written in Erlang
Huge reliability in distributed systems
Run on several operational system and languages
Has many plugins
Topologies
Standalone
Cluster
Topologies
Federation
Installing
&
Configuring
Let's install and setup:
* The RabbitMQ installation
(Server)
* RabbitMQ management panel installation
(Plugin)
* Virtual host and user configurations
More infos in http://www.rabbitmq.com/download.html
It works in http://<localhost>:15672
Management Panel Plugin
User configurations
We ❤️ all programming languages...
... But...
... We ❤️❤️❤️❤️PHP!
The AMQP library
https://github.com/php-amqplib/php-amqplib
$ composer require php-amqplib/php-amqplib
Creating a Publisher
Use your favorite language. There will be a library for this.
Create a connection and channel
Create your message and send to exchange =)
Creating a Publisher
Queue_declare ( )
'Name' - Name of queue
'Durable' - Are we going to survive the restart?
'Auto_delete' - What happens after the last message?
'Nowait' - Should we wait for an answer?
Creating a Consumer
Don't forget the connection and channel
Let's consume the queue items
Meanwhile in the message broker...
Choosing a exchange
Exchange Declaration
Fanout Exchange
Exchange
Queues
Direct Exchange
Exchange
Queues
Archive
Crop
Resize
Topic Exchange
Exchange
Queues
*.web
*.log
Headers Exchange
Exchange
Queues
Archive
Crop
Resize
Use header informations as routing key
Some interesting solutions
Dead Letter
Exchange
Publisher
Queue
Consumer
Exchange
Reject Queue
Multiple Consumers/Services
Exchange
Publisher
Queue
Consumer
Queue
Queue
Cloud
DB
Delayed Message
Exchange
Publisher
Delay Queue
Exchange
Queue
Get to know more about RabbitMQ...
http://www.rabbitmq.com/getstarted.html
Thanks and see you soon ;)
@magodoy88
magodoycruz@gmail.com
Filas e Mensageria @DarkmiraTour
By Marcela Godoy Cruz
Filas e Mensageria @DarkmiraTour
- 558