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

Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Anthony Dahanne
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
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
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 

Recently uploaded (20)

Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024Not a Kubernetes fan? The state of PaaS in 2024
Not a Kubernetes fan? The state of PaaS in 2024
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
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
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 

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!