SlideShare a Scribd company logo
1 of 25
Download to read offline
intro and messaging patterns
javier arias losada @javier_arilos
amqp and rabbitmq
introduction to messaging
messaging
● provides asynchronous communications
● loosely coupled modules / processes
● MoM => Message Oriented Middleware
amqp concepts (i)
amqp is a message oriented wire-level protocol
● message broker: receives and dispatches msgs
using AMQP
● connection physical connection (eg: tcp/ip)
● channel: allows n clients over one connection
consumerproducer
producer consumer
amqp concepts (ii)
consumerproducer
producer consumer
Clients produce and
consume messages.
Exchanges Route and filter
messages to queues: binding
rules, direct, one-to-one,
fanout, topic, headers
Queues buffer messages between
producers and consumers
Messages are always:
>> sent to exchanges
>> consumed from queues
escenario 1
● producing and consuming, simplest routing
examples using Python, pika and rabbitmq, everything should apply to other
languages, libraries and amqp brokers
‘important’ messages must be sent to queue ‘important-jobs’
consumerproducer
source code for the example: https://gist.github.com/javierarilos/9348168
step 1- connect & channel setup
from pika import BlockingConnection, ConnectionParameters
conn = BlockingConnection(ConnectionParameters('localhost'))
ch = conn.channel()
consumerproducer
Same code for consumer and
producer
step 2- declare exchange
Declare an exchange, important parameters:
● name: if exists, nothing is done
● type: direct, fanout, pub-sub, headers
● durable: must exchange be kept between server restarts?
● autodelete: must exchange be deleted when not in use?
● internal: is it for internal routing use, or public to clients?
ch.exchange_declare(exchange='important', type='direct')
consumerproducer
exchange: important
type: direct
step 3- declare queue
Declare a queue, important parameters:
● name: if exists, nothing is done
● durable: must queue declaration be kept between server restarts?
● exclusive: Is this the only connection that can consume from the queue?
● autodelete: must queue be deleted when not in use?
ch.queue_declare(queue='important-jobs')
consumerproducer
exchange: important
type: direct
queue: important-jobs
step 4- bind queue and exchange
ch.queue_bind(exchange='important', queue='important-jobs', routing_key='important')
consumerproducer
exchange: important
type: direct
queue: important-jobs
routing_key:
important
Binding a queue and exchange:
● establishes a route (exchange => queue)
● based on a criteria (exchange type + routing key)
Here: when producer sends a message to ‘important’ exchange with routing key
‘important’, message will be forwarded to queue ‘important-jobs’.
step 5- send the message
ch.basic_publish(exchange='important', routing_key='important', body='new important task')
consumerproducer
exchange: important
type: direct
queue: important-jobs
routing_key:
important
Bonus track: default exchange, forwards to a queue, without any exchange declaration:
default exchange’s name is empty string = ‘’
routing_key is the queue name ‘important-jobs’
ch.basic_publish(exchange=’’, routing_key='important-jobs', body=’def exch important task')
step 6- consume the message
method_frame, header_frame, body = ch.basic_get('important-jobs')
print body
ch.basic_ack(method_frame.delivery_tag)
consumerproducer
exchange: important
type: direct
queue: important-jobs
routing_key:
important
Messages must be acknowledged
escenario 2
● default exchange in more detail
● message to two queues, depending on routing key
‘important’ messages must be sent to queues ‘important-jobs’ and ‘traces’
consumerproducer
consumer
step 1- create & bind new queue
ch.queue_declare(queue='traces')
ch.queue_bind(exchange='important', queue='traces', routing_key='important')
ch.basic_publish(exchange='important', routing_key='important', body='[another task to be handled]')
consumerproducer
exchange: important
type: direct
queue: important-jobs
routing_key:
important
consumer
routing_key:
important
queue: traces
step 2- consuming from both
consumerproducer
exchange: important
type: direct
queue: important-jobs
consumer
routing_key:
important
queue: traces
routing_key:
important
● Binding the new ‘traces’ queue to existing ‘important’ exchange does
not affect publishing code.
● Consumers and queues may be added dynamically without affecting the
producer.
escenario 3
● 2 x (binding + routing-key) => to 1 queue
● exchange to exchange binding
● headers exchange
‘customer’ messages to ‘important’ exchange must be sent to different queues
depending on the operation to perform (‘signup’, ‘update’) and to ‘traces’
traces
consumer
producer
update
consumer
signup
consumer
step 1- bind traces, declare q’s
routing_key:
customer traces
consumer
producer
update
consumer
signup
consumer
exchange: important
type: direct
queue: traces
queue: signup
queue: update
‘traces’ queue is bound to
‘important’ exch with two routing
keys: ‘customer’ and ‘important’
ch.queue_bind(exchange='important', queue='traces', routing_key='customer')
ch.queue_declare(queue='signup')
ch.queue_declare(queue='update')
exchange: important
type: direct
traces
consumer
producer
update
consumer
signup
consumer
queue: traces
queue: signup
queue: update
exchange: customer
type: headers
routing_key:
customer
step 2- customer exchange & bind
ch.exchange_declare(exchange='customer', type='headers')
ch.exchange_bind(source='important', destination='customer', routing_key='customer')
ch.queue_bind(exchange='customer', queue='signup',
arguments={'operation': 'signup', 'x-match':'any'})
ch.queue_bind(exchange='customer', queue='update',
arguments={'operation': 'update', 'x-match':'any'})
step 3- customer signup message
ch.basic_publish(exchange='important', routing_key='customer',
body='cust num=25', properties=BasicProperties(headers=s{'operation': 'signup'}))
method_frame, header_frame, msg = ch.basic_get('signup')
print "msg received from queue 'signup' : ", msg
ch.basic_ack(method_frame.delivery_tag)
routing_key:
customer traces
consumer
producer
update
consumer
signup
consumer
exchange: important
type: direct
queue: traces
queue: signup
queue: update
exchange: customer
type: headers
msg also routed to traces queue
bonus: topic exchanges
traces
consumer
producer
customer
consumer
signup
consumerexchange: operations
type: topic
queue: traces
queue: signup
queue: update
r_k: #
r_k: *.signup
r_k: customer.*
topic exchanges allow to route messages based on topics.
Examples from escenario 3:
○ Producer sends with routing keys: ‘customer.signup’, ‘customer.update’
○ ‘traces’ consumer subscribes to ‘#’ that means all routing keys
○ ‘signup’ customer consumer subscribes to ‘customer.signup’
○ Consumer wanting all customer operations: ‘customer.*’
○ Consumer wanting all signup operations: *.signup’
escenario 4
● DeadLetter exchanges in RabbitMQ
What will we do with a message RabbitMQ cannot deliver?
(on client rejection, timeout, queue length exceeded)
By default those messages are dropped, we want not to lose them
consumerproducer
step 1- create rejected-jobs
ch.exchange_declare(exchange='rejected-jobs', type='direct')
ch.queue_declare(queue='rejected-jobs')
ch.queue_bind(exchange='rejected-jobs', queue='rejected-jobs', routing_key='important')
consumerproducer
queue: rejected-jobs
exchange: rejected-jobs
type: direct
step 2- deadlettr important-jobs
ch.queue_delete('important-jobs')
ch.queue_declare(queue='important-jobs', arguments={'x-dead-letter-exchange': 'rejected-jobs'})
ch.queue_bind(exchange='important', queue='important-jobs', routing_key='important')
consumerproducer
queue: rejected-jobs
exchange: rejected-jobs
type: direct
exchange: important
type: direct
routing_key:
important
x-dead-letter-exchange:
rejected-jobs
step 3- consumer rejects job
ch.basic_publish(exchange='important', routing_key='important', body='[unparseable message]')
method_frame, header_frame, important_job = ch.basic_get('important-jobs')
ch.basic_reject(method_frame.delivery_tag, requeue=False)
method_frame, header_frame, rejected_job = ch.basic_get('rejected-jobs')
ch.basic_ack(method_frame.delivery_tag)
consumerproducer
queue: rejected-jobs
exchange: rejected-jobs
type: direct
exchange: important
type: direct
routing_key:
important
x-dead-letter-exchange:
rejected-jobs
What are you waiting to start working with RabbitMQ?
It’s fun!
Questions?
Thank you for attending.

More Related Content

What's hot

RabbitMQ vs Apache Kafka Part II Webinar
RabbitMQ vs Apache Kafka Part II WebinarRabbitMQ vs Apache Kafka Part II Webinar
RabbitMQ vs Apache Kafka Part II WebinarErlang Solutions
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQAll Things Open
 
Rabbitmq & Kafka Presentation
Rabbitmq & Kafka PresentationRabbitmq & Kafka Presentation
Rabbitmq & Kafka PresentationEmre Gündoğdu
 
Easy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQPEasy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQPRabbit MQ
 
Introduction To RabbitMQ
Introduction To RabbitMQIntroduction To RabbitMQ
Introduction To RabbitMQKnoldus Inc.
 
High powered messaging with RabbitMQ
High powered messaging with RabbitMQHigh powered messaging with RabbitMQ
High powered messaging with RabbitMQJames Carr
 
Introduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQIntroduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQDmitriy Samovskiy
 
Rabbit MQ introduction
Rabbit MQ introductionRabbit MQ introduction
Rabbit MQ introductionShirish Bari
 
Rabbitmq an amqp message broker
Rabbitmq an amqp message brokerRabbitmq an amqp message broker
Rabbitmq an amqp message brokerANASYS
 
RabbitMQ with python and ruby RuPy 2009
RabbitMQ with python and ruby RuPy 2009RabbitMQ with python and ruby RuPy 2009
RabbitMQ with python and ruby RuPy 2009Paolo Negri
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message BrokerMartin Toshev
 
Full Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.jsFull Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.jsJavier Arias Losada
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data IngestionAlvaro Videla
 
[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging QueuesNaukri.com
 
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQAlvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQTanya Denisyuk
 

What's hot (20)

RabbitMQ vs Apache Kafka Part II Webinar
RabbitMQ vs Apache Kafka Part II WebinarRabbitMQ vs Apache Kafka Part II Webinar
RabbitMQ vs Apache Kafka Part II Webinar
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQ
 
Rabbitmq & Kafka Presentation
Rabbitmq & Kafka PresentationRabbitmq & Kafka Presentation
Rabbitmq & Kafka Presentation
 
Easy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQPEasy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQP
 
AMQP for phpMelb
AMQP for phpMelbAMQP for phpMelb
AMQP for phpMelb
 
Introduction To RabbitMQ
Introduction To RabbitMQIntroduction To RabbitMQ
Introduction To RabbitMQ
 
High powered messaging with RabbitMQ
High powered messaging with RabbitMQHigh powered messaging with RabbitMQ
High powered messaging with RabbitMQ
 
Introduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQIntroduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQ
 
Rabbit MQ introduction
Rabbit MQ introductionRabbit MQ introduction
Rabbit MQ introduction
 
Rabbitmq an amqp message broker
Rabbitmq an amqp message brokerRabbitmq an amqp message broker
Rabbitmq an amqp message broker
 
Amqp Basic
Amqp BasicAmqp Basic
Amqp Basic
 
RabbitMQ with python and ruby RuPy 2009
RabbitMQ with python and ruby RuPy 2009RabbitMQ with python and ruby RuPy 2009
RabbitMQ with python and ruby RuPy 2009
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message Broker
 
Full Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.jsFull Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.js
 
RabbitMQ
RabbitMQRabbitMQ
RabbitMQ
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data Ingestion
 
[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues
 
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQAlvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
 

Similar to Rabbitmq, amqp Intro - Messaging Patterns

Streaming Way to Webscale: How We Scale Bitly via Streaming
Streaming Way to Webscale: How We Scale Bitly via StreamingStreaming Way to Webscale: How We Scale Bitly via Streaming
Streaming Way to Webscale: How We Scale Bitly via StreamingAll Things Open
 
SF Microservices Meetup - May 2017
SF Microservices Meetup - May 2017SF Microservices Meetup - May 2017
SF Microservices Meetup - May 2017Erin Kumar
 
KFServing - Serverless Model Inferencing
KFServing - Serverless Model InferencingKFServing - Serverless Model Inferencing
KFServing - Serverless Model InferencingAnimesh Singh
 
RabbitMQ + CouchDB = Awesome
RabbitMQ + CouchDB = AwesomeRabbitMQ + CouchDB = Awesome
RabbitMQ + CouchDB = AwesomeLenz Gschwendtner
 
Learn Anypoint MQ | MuleSoft Mysore Meetup #7
Learn Anypoint MQ | MuleSoft Mysore Meetup #7Learn Anypoint MQ | MuleSoft Mysore Meetup #7
Learn Anypoint MQ | MuleSoft Mysore Meetup #7MysoreMuleSoftMeetup
 
What we learnt at carousell tw for golang gathering #31
What we learnt at carousell tw for golang gathering #31What we learnt at carousell tw for golang gathering #31
What we learnt at carousell tw for golang gathering #31Ronald Hsu
 
Swift distributed tracing method and tools v2
Swift distributed tracing method and tools v2Swift distributed tracing method and tools v2
Swift distributed tracing method and tools v2zhang hua
 
Differential Machine Learning Masterclass
Differential Machine Learning MasterclassDifferential Machine Learning Masterclass
Differential Machine Learning MasterclassAntoine Savine
 
Using message queues for distributed computing on Kubernetes
Using message queues for distributed computing on KubernetesUsing message queues for distributed computing on Kubernetes
Using message queues for distributed computing on KubernetesSelin Gungor
 
Understanding Business APIs through statistics
Understanding Business APIs through statisticsUnderstanding Business APIs through statistics
Understanding Business APIs through statisticsWSO2
 
HHM-3540: The IBM MQ Light API: From Developer Laptop to Enterprise Data Cen...
 HHM-3540: The IBM MQ Light API: From Developer Laptop to Enterprise Data Cen... HHM-3540: The IBM MQ Light API: From Developer Laptop to Enterprise Data Cen...
HHM-3540: The IBM MQ Light API: From Developer Laptop to Enterprise Data Cen...Matt Leming
 
Client-server architecture (clientserver) is a network architecture .pdf
Client-server architecture (clientserver) is a network architecture .pdfClient-server architecture (clientserver) is a network architecture .pdf
Client-server architecture (clientserver) is a network architecture .pdffabmallkochi
 
Revolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn PipelinesRevolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn PipelinesPhilip Goddard
 
Service Mesh - kilometer 30 in a microservice marathon
Service Mesh - kilometer 30 in a microservice marathonService Mesh - kilometer 30 in a microservice marathon
Service Mesh - kilometer 30 in a microservice marathonMichael Hofmann
 

Similar to Rabbitmq, amqp Intro - Messaging Patterns (20)

Streaming Way to Webscale: How We Scale Bitly via Streaming
Streaming Way to Webscale: How We Scale Bitly via StreamingStreaming Way to Webscale: How We Scale Bitly via Streaming
Streaming Way to Webscale: How We Scale Bitly via Streaming
 
SF Microservices Meetup - May 2017
SF Microservices Meetup - May 2017SF Microservices Meetup - May 2017
SF Microservices Meetup - May 2017
 
KFServing - Serverless Model Inferencing
KFServing - Serverless Model InferencingKFServing - Serverless Model Inferencing
KFServing - Serverless Model Inferencing
 
RabbitMQ + CouchDB = Awesome
RabbitMQ + CouchDB = AwesomeRabbitMQ + CouchDB = Awesome
RabbitMQ + CouchDB = Awesome
 
Learn Anypoint MQ | MuleSoft Mysore Meetup #7
Learn Anypoint MQ | MuleSoft Mysore Meetup #7Learn Anypoint MQ | MuleSoft Mysore Meetup #7
Learn Anypoint MQ | MuleSoft Mysore Meetup #7
 
What we learnt at carousell tw for golang gathering #31
What we learnt at carousell tw for golang gathering #31What we learnt at carousell tw for golang gathering #31
What we learnt at carousell tw for golang gathering #31
 
Swift distributed tracing method and tools v2
Swift distributed tracing method and tools v2Swift distributed tracing method and tools v2
Swift distributed tracing method and tools v2
 
Differential Machine Learning Masterclass
Differential Machine Learning MasterclassDifferential Machine Learning Masterclass
Differential Machine Learning Masterclass
 
Using message queues for distributed computing on Kubernetes
Using message queues for distributed computing on KubernetesUsing message queues for distributed computing on Kubernetes
Using message queues for distributed computing on Kubernetes
 
Understanding Business APIs through statistics
Understanding Business APIs through statisticsUnderstanding Business APIs through statistics
Understanding Business APIs through statistics
 
Introduction to MPI
Introduction to MPIIntroduction to MPI
Introduction to MPI
 
Declaration of variables
Declaration of variablesDeclaration of variables
Declaration of variables
 
HHM-3540: The IBM MQ Light API: From Developer Laptop to Enterprise Data Cen...
 HHM-3540: The IBM MQ Light API: From Developer Laptop to Enterprise Data Cen... HHM-3540: The IBM MQ Light API: From Developer Laptop to Enterprise Data Cen...
HHM-3540: The IBM MQ Light API: From Developer Laptop to Enterprise Data Cen...
 
Client-server architecture (clientserver) is a network architecture .pdf
Client-server architecture (clientserver) is a network architecture .pdfClient-server architecture (clientserver) is a network architecture .pdf
Client-server architecture (clientserver) is a network architecture .pdf
 
C++ basic.ppt
C++ basic.pptC++ basic.ppt
C++ basic.ppt
 
IBM_Q-Rep-Tutorial
IBM_Q-Rep-TutorialIBM_Q-Rep-Tutorial
IBM_Q-Rep-Tutorial
 
Revolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn PipelinesRevolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
Revolutionise your Machine Learning Workflow using Scikit-Learn Pipelines
 
Geeky.week3.rabbitmq
Geeky.week3.rabbitmqGeeky.week3.rabbitmq
Geeky.week3.rabbitmq
 
Functions in C++.pdf
Functions in C++.pdfFunctions in C++.pdf
Functions in C++.pdf
 
Service Mesh - kilometer 30 in a microservice marathon
Service Mesh - kilometer 30 in a microservice marathonService Mesh - kilometer 30 in a microservice marathon
Service Mesh - kilometer 30 in a microservice marathon
 

More from Javier Arias Losada

Why do lazy developers write beautiful code?
Why do lazy developers write beautiful code?Why do lazy developers write beautiful code?
Why do lazy developers write beautiful code?Javier Arias Losada
 
Europython - Machine Learning for dummies with Python
Europython - Machine Learning for dummies with PythonEuropython - Machine Learning for dummies with Python
Europython - Machine Learning for dummies with PythonJavier Arias Losada
 
Pybcn machine learning for dummies with python
Pybcn machine learning for dummies with pythonPybcn machine learning for dummies with python
Pybcn machine learning for dummies with pythonJavier Arias Losada
 
OSCON - ES6 metaprogramming unleashed
OSCON -  ES6 metaprogramming unleashedOSCON -  ES6 metaprogramming unleashed
OSCON - ES6 metaprogramming unleashedJavier Arias Losada
 
Elastically scalable architectures with microservices. The end of the monolith?
Elastically scalable architectures with microservices. The end of the monolith?Elastically scalable architectures with microservices. The end of the monolith?
Elastically scalable architectures with microservices. The end of the monolith?Javier Arias Losada
 
NoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel Messaging
NoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel MessagingNoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel Messaging
NoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel MessagingJavier Arias Losada
 
From Java to Python: beating the Stockholm syndrome
From Java to Python: beating the Stockholm syndromeFrom Java to Python: beating the Stockholm syndrome
From Java to Python: beating the Stockholm syndromeJavier Arias Losada
 

More from Javier Arias Losada (8)

Why do lazy developers write beautiful code?
Why do lazy developers write beautiful code?Why do lazy developers write beautiful code?
Why do lazy developers write beautiful code?
 
Europython - Machine Learning for dummies with Python
Europython - Machine Learning for dummies with PythonEuropython - Machine Learning for dummies with Python
Europython - Machine Learning for dummies with Python
 
Pybcn machine learning for dummies with python
Pybcn machine learning for dummies with pythonPybcn machine learning for dummies with python
Pybcn machine learning for dummies with python
 
OSCON - ES6 metaprogramming unleashed
OSCON -  ES6 metaprogramming unleashedOSCON -  ES6 metaprogramming unleashed
OSCON - ES6 metaprogramming unleashed
 
ES6 metaprogramming unleashed
ES6 metaprogramming unleashedES6 metaprogramming unleashed
ES6 metaprogramming unleashed
 
Elastically scalable architectures with microservices. The end of the monolith?
Elastically scalable architectures with microservices. The end of the monolith?Elastically scalable architectures with microservices. The end of the monolith?
Elastically scalable architectures with microservices. The end of the monolith?
 
NoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel Messaging
NoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel MessagingNoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel Messaging
NoSQL Matters BCN 2013. Sprayer Low Latency, Reliable, Mutichannel Messaging
 
From Java to Python: beating the Stockholm syndrome
From Java to Python: beating the Stockholm syndromeFrom Java to Python: beating the Stockholm syndrome
From Java to Python: beating the Stockholm syndrome
 

Recently uploaded

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 

Recently uploaded (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 

Rabbitmq, amqp Intro - Messaging Patterns

  • 1. intro and messaging patterns javier arias losada @javier_arilos amqp and rabbitmq
  • 2. introduction to messaging messaging ● provides asynchronous communications ● loosely coupled modules / processes ● MoM => Message Oriented Middleware
  • 3. amqp concepts (i) amqp is a message oriented wire-level protocol ● message broker: receives and dispatches msgs using AMQP ● connection physical connection (eg: tcp/ip) ● channel: allows n clients over one connection consumerproducer producer consumer
  • 4. amqp concepts (ii) consumerproducer producer consumer Clients produce and consume messages. Exchanges Route and filter messages to queues: binding rules, direct, one-to-one, fanout, topic, headers Queues buffer messages between producers and consumers Messages are always: >> sent to exchanges >> consumed from queues
  • 5. escenario 1 ● producing and consuming, simplest routing examples using Python, pika and rabbitmq, everything should apply to other languages, libraries and amqp brokers ‘important’ messages must be sent to queue ‘important-jobs’ consumerproducer source code for the example: https://gist.github.com/javierarilos/9348168
  • 6. step 1- connect & channel setup from pika import BlockingConnection, ConnectionParameters conn = BlockingConnection(ConnectionParameters('localhost')) ch = conn.channel() consumerproducer Same code for consumer and producer
  • 7. step 2- declare exchange Declare an exchange, important parameters: ● name: if exists, nothing is done ● type: direct, fanout, pub-sub, headers ● durable: must exchange be kept between server restarts? ● autodelete: must exchange be deleted when not in use? ● internal: is it for internal routing use, or public to clients? ch.exchange_declare(exchange='important', type='direct') consumerproducer exchange: important type: direct
  • 8. step 3- declare queue Declare a queue, important parameters: ● name: if exists, nothing is done ● durable: must queue declaration be kept between server restarts? ● exclusive: Is this the only connection that can consume from the queue? ● autodelete: must queue be deleted when not in use? ch.queue_declare(queue='important-jobs') consumerproducer exchange: important type: direct queue: important-jobs
  • 9. step 4- bind queue and exchange ch.queue_bind(exchange='important', queue='important-jobs', routing_key='important') consumerproducer exchange: important type: direct queue: important-jobs routing_key: important Binding a queue and exchange: ● establishes a route (exchange => queue) ● based on a criteria (exchange type + routing key) Here: when producer sends a message to ‘important’ exchange with routing key ‘important’, message will be forwarded to queue ‘important-jobs’.
  • 10. step 5- send the message ch.basic_publish(exchange='important', routing_key='important', body='new important task') consumerproducer exchange: important type: direct queue: important-jobs routing_key: important Bonus track: default exchange, forwards to a queue, without any exchange declaration: default exchange’s name is empty string = ‘’ routing_key is the queue name ‘important-jobs’ ch.basic_publish(exchange=’’, routing_key='important-jobs', body=’def exch important task')
  • 11. step 6- consume the message method_frame, header_frame, body = ch.basic_get('important-jobs') print body ch.basic_ack(method_frame.delivery_tag) consumerproducer exchange: important type: direct queue: important-jobs routing_key: important Messages must be acknowledged
  • 12. escenario 2 ● default exchange in more detail ● message to two queues, depending on routing key ‘important’ messages must be sent to queues ‘important-jobs’ and ‘traces’ consumerproducer consumer
  • 13. step 1- create & bind new queue ch.queue_declare(queue='traces') ch.queue_bind(exchange='important', queue='traces', routing_key='important') ch.basic_publish(exchange='important', routing_key='important', body='[another task to be handled]') consumerproducer exchange: important type: direct queue: important-jobs routing_key: important consumer routing_key: important queue: traces
  • 14. step 2- consuming from both consumerproducer exchange: important type: direct queue: important-jobs consumer routing_key: important queue: traces routing_key: important ● Binding the new ‘traces’ queue to existing ‘important’ exchange does not affect publishing code. ● Consumers and queues may be added dynamically without affecting the producer.
  • 15. escenario 3 ● 2 x (binding + routing-key) => to 1 queue ● exchange to exchange binding ● headers exchange ‘customer’ messages to ‘important’ exchange must be sent to different queues depending on the operation to perform (‘signup’, ‘update’) and to ‘traces’ traces consumer producer update consumer signup consumer
  • 16. step 1- bind traces, declare q’s routing_key: customer traces consumer producer update consumer signup consumer exchange: important type: direct queue: traces queue: signup queue: update ‘traces’ queue is bound to ‘important’ exch with two routing keys: ‘customer’ and ‘important’ ch.queue_bind(exchange='important', queue='traces', routing_key='customer') ch.queue_declare(queue='signup') ch.queue_declare(queue='update')
  • 17. exchange: important type: direct traces consumer producer update consumer signup consumer queue: traces queue: signup queue: update exchange: customer type: headers routing_key: customer step 2- customer exchange & bind ch.exchange_declare(exchange='customer', type='headers') ch.exchange_bind(source='important', destination='customer', routing_key='customer') ch.queue_bind(exchange='customer', queue='signup', arguments={'operation': 'signup', 'x-match':'any'}) ch.queue_bind(exchange='customer', queue='update', arguments={'operation': 'update', 'x-match':'any'})
  • 18. step 3- customer signup message ch.basic_publish(exchange='important', routing_key='customer', body='cust num=25', properties=BasicProperties(headers=s{'operation': 'signup'})) method_frame, header_frame, msg = ch.basic_get('signup') print "msg received from queue 'signup' : ", msg ch.basic_ack(method_frame.delivery_tag) routing_key: customer traces consumer producer update consumer signup consumer exchange: important type: direct queue: traces queue: signup queue: update exchange: customer type: headers msg also routed to traces queue
  • 19. bonus: topic exchanges traces consumer producer customer consumer signup consumerexchange: operations type: topic queue: traces queue: signup queue: update r_k: # r_k: *.signup r_k: customer.* topic exchanges allow to route messages based on topics. Examples from escenario 3: ○ Producer sends with routing keys: ‘customer.signup’, ‘customer.update’ ○ ‘traces’ consumer subscribes to ‘#’ that means all routing keys ○ ‘signup’ customer consumer subscribes to ‘customer.signup’ ○ Consumer wanting all customer operations: ‘customer.*’ ○ Consumer wanting all signup operations: *.signup’
  • 20. escenario 4 ● DeadLetter exchanges in RabbitMQ What will we do with a message RabbitMQ cannot deliver? (on client rejection, timeout, queue length exceeded) By default those messages are dropped, we want not to lose them consumerproducer
  • 21. step 1- create rejected-jobs ch.exchange_declare(exchange='rejected-jobs', type='direct') ch.queue_declare(queue='rejected-jobs') ch.queue_bind(exchange='rejected-jobs', queue='rejected-jobs', routing_key='important') consumerproducer queue: rejected-jobs exchange: rejected-jobs type: direct
  • 22. step 2- deadlettr important-jobs ch.queue_delete('important-jobs') ch.queue_declare(queue='important-jobs', arguments={'x-dead-letter-exchange': 'rejected-jobs'}) ch.queue_bind(exchange='important', queue='important-jobs', routing_key='important') consumerproducer queue: rejected-jobs exchange: rejected-jobs type: direct exchange: important type: direct routing_key: important x-dead-letter-exchange: rejected-jobs
  • 23. step 3- consumer rejects job ch.basic_publish(exchange='important', routing_key='important', body='[unparseable message]') method_frame, header_frame, important_job = ch.basic_get('important-jobs') ch.basic_reject(method_frame.delivery_tag, requeue=False) method_frame, header_frame, rejected_job = ch.basic_get('rejected-jobs') ch.basic_ack(method_frame.delivery_tag) consumerproducer queue: rejected-jobs exchange: rejected-jobs type: direct exchange: important type: direct routing_key: important x-dead-letter-exchange: rejected-jobs
  • 24. What are you waiting to start working with RabbitMQ? It’s fun!