Slide 1

Slide 1 text

Working with RabbitMQ and PHP with PHP-AmqpLib 7th July 2021 ORGANISERS

Slide 2

Slide 2 text

Web Developer and Software Engineer since 2011. Brazilian living in Ireland. Data Science and DevOps student. Member of PHP DF and PHP Dublin community. Speaker, Father and Guitar player WHO AM I? @Bruno_HSouza

Slide 3

Slide 3 text

THE SCHEDULE

Slide 4

Slide 4 text

● Context of the Use Case ● Concepts for Message Systems ● Use Case Scenario ● PHP-AMQP-LIB ● Conclusion

Slide 5

Slide 5 text

CONTEXT Use Case Story WHO IS SMARTBOX AND HOW DO WE WORK WITH RABBITMQ?

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

AM~Key-P

Slide 8

Slide 8 text

Initial Architecture

Slide 9

Slide 9 text

Architecture After Some Time

Slide 10

Slide 10 text

With an ESB Architecture

Slide 11

Slide 11 text

Sync Vs Async

Slide 12

Slide 12 text

CONCEPTS FOR MESSAGING SYSTEM

Slide 13

Slide 13 text

● Is a technology that enables a communication with: ○ High-speed; ○ Synchronous and/or asynchronous approach; ○ Point-to-point (P2P); ○ Messages (packs of data) between applications; Messaging System

Slide 14

Slide 14 text

● Is an messaging open-source protocol that enables applications to communicate with messaging brokers; ● Defines both the network layer protocol and a high-level architecture for message brokers AMQP - Advanced Message Queuing Protocol

Slide 15

Slide 15 text

● Acts as a buffer that stores messages that are consumed later; ○ Name; ○ Durable; ○ Exclusive; ○ Auto-delete; ○ Arguments (TTL, length limit) Queues

Slide 16

Slide 16 text

● Entities where messages are sent; ● Take a message and route it into zero or more queues; ● Can have some types like: ○ Direct; ○ Fanout; ○ Topic; ○ Headers; Exchanges

Slide 17

Slide 17 text

● is a relation between a queue and an exchange consisting of a set of rules that the exchange uses to route messages to queues; Bindings (routes)

Slide 18

Slide 18 text

● Is a virtual connection inside a connection, between two AMQP peers. ● Message publishing or consuming to or from a queue is performed over a channel (AMQP). ● A channel is multiplexed, one single connection can have multiple channels. Channel

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Use Case Scenario How was the application before implementing the PHP-AMQPLIB

Slide 21

Slide 21 text

PHP Native AMQP and STOMP PHP Native Driver Stomp Driver

Slide 22

Slide 22 text

● Faster than any other library due to its native extension written in C; ● Already implemented in the application; ● Do not offer support to consume messages in a non-blocking way; ● Can not listen to posix signals while consuming; Native AMQP Driver

Slide 23

Slide 23 text

● Simple (or Streaming) Text Orientated Messaging Protocol; ● Simple and easy to implement; ● Provides an interoperable wire format to communicate with any message broker; ● Frame based protocol, with frames modelled on HTTP; ● Do not offer support to consume messages in a non-blocking way; Stomp Driver

Slide 24

Slide 24 text

● Consume messages in a non-blocking way on our ESB; ● Implement a driver with support to Posix signals; A new challenge

Slide 25

Slide 25 text

Blocking Process PDF Creation Request Producer Publish Process Consume Process Publish Worker

Slide 26

Slide 26 text

Non-blocking Process Consume Process Worker Event Loop Callback

Slide 27

Slide 27 text

● To find a way to implement a non-blocking consume() function with the native driver ● Implement a new driver with support to Posix signals; ● Work with Symfony Messenger and change our architecture; Possible Solutions

Slide 28

Slide 28 text

It worths to adapt the library PHP-AMQPLIB into the framework even with a lot of work and creation of a second version of the app Decision

Slide 29

Slide 29 text

PHP-AMQPLIB

Slide 30

Slide 30 text

● This library is a pure PHP implementation of the AMQP 0-9-1 protocol. ● It's been tested and used for examples by RabbitMQ; ● Offers the possibility to consume messages in a non-blocking way; ● Signals can be dispatched to the worker even if it's consuming messages; ● Offers other options like: heartbeats, channels, respect POSIX signals, and multiple hosts PHP-AMQPLIB

Slide 31

Slide 31 text

PHP-AMQPLIB Configure

Slide 32

Slide 32 text

PHP-AMQPLIB Connect

Slide 33

Slide 33 text

Multiple Connections

Slide 34

Slide 34 text

Using a channel

Slide 35

Slide 35 text

Using queues

Slide 36

Slide 36 text

Sending a message

Slide 37

Slide 37 text

Consume

Slide 38

Slide 38 text

Async Consume Callback 1st step 2nd step 3rd step 4th step

Slide 39

Slide 39 text

Signals

Slide 40

Slide 40 text

Benchmark Milliseconds taken by request

Slide 41

Slide 41 text

References ● RabbitMQ Documentation ● CloudAMQP blog ● Smartbox - Medium ● PHP-AMQPLIB

Slide 42

Slide 42 text

No content