2. Who am I? What we do?
- Marçal Berga, born in Roda de Ter, from Lluçanès, living in miami
- PHP Lover for 6+ years
- Unit tester
- Project Manager at Edicions Digitals Del Camp.
- National level digital newspapers
- +10 content sites
- Over 3M daily unique visitors
- Top 10 Catalan newspaper in catalunya (delcamp.cat)
- 100% custom software
delcamp.cat | catalunyadiari.cat | diaridecatalunya.cat | espanadiario.es | horoscopomagico.com | caracterurbano.com | laguiafemenenia.com |
catalunyacuina.cat | valenciadiari.com | ...
4. RabbitMQ
- Message Broker
- Native AMQP (advanced messaging queue protocol) support
- STOMP (Simple Text Oriented Messaging Protocol) via plugin
- MQTT (Message Queuing Telemetry Transport) via plugin
- Made with Erlang
- Cluster ready
- HTTP API for stats and management
- Multiple plugins
5. What we’ll see?
- Producer:
- Who creates the messages and pushes them to RabbitMQ.
- Message:
- data to transfer between apps/services
- Exchange:
- Receives messages and routes them to queues.
- Queue:
- just that, a queue.
- Consumer/worker:
- Takes messages from queue and does things.
- Examples are made with python and pika library.
6. Producer
- Creates messages and sends them to exchange.
- Important: make sure queue and exchange exist and are binded. If rabbit can
not route message it will be returned or lost in case of miscunfiguration.
7. Message
- Contents all information passed between services/apps
- Contents information/headers
- Automatically added by broker (x-something)
- Added by publisher (opaque to broker)
- Routing key
- Body
8. Exchange
- Receives messages from publisher.
- Routes messages to correct queue.
- Acks messages to publisher.
- Fanout Exchange:
- delivers messages to ALL binded queues.
- Direct exchange:
- routes message by full routing key.
- Topic exchange:
- routes message by routing key with woldcars.
9. Fanout routing
Publisher Exchange
Queue 1
Queue 2
Queue 3
Delivers message to ALL binded queues, without working with routes.
So, we can send any message and it will be delivered to ALL queues
10. Direct routing
Publisher Exchange
Queue 1
Queue 2
Queue 3
route.1
route.2
route.3
Delivers message to matching route binded queues.
So, if we send a message with routing = “route.1” it will be delivered to Queue 1 and so on
11. Topic routing
Publisher Exchange
Queue 1
Queue 2
Queue 3
app.log.*
app.notify.*
app.#
Delivers message to rules based route(s) binded queues.
Using wildcards (* and #) we can set rules of routing. * mean any ONE value; # mean ANY ANY values.
- app.log.error and app.log.info will be delivered to Queue 1 and Queue 3.
- app.notify.admin will be delivered to Queue 2 and Queue 3.
- app.random.facts.longer.routing will be delivered to Queue 3.
13. Consuming messages
Consumer gets messages from a queue and does magic with that.
Consumer should acknowledge, reject or deny message.
- Acknowledge => OK
- Reject => Won’t do
- Deny => KO
Rabbit delivers message with a delivery tag for each message.
- Delivery tag is not unique!
14. Dead-lettering
Messages nacked can be requeued to same queue, discarted or dead-lettered.
- We need a dead letter exchange (DLX) created.
- Queue will have x-dead-letter-exchange attribute.
- Exchanges also can have a DLX to dead-letter messages not queued.
- Works like any other exchange nor queue.