MESSAGING WITH 
AMQP AND RABBITMQ
What is AMQP? 
AMQP (Advanced Message 
Queuing Protocol) is a 
networking protocol that enables 
conforming client applications to 
communicate with conforming 
messaging middleware brokers.
WHAT ARE 
BROKERS 
Messaging brokers receive 
messages from publishers 
(applications that publish them, 
also known as producers) and 
route them to consumers 
(applications that process them).
EXAMPLE OF 
BROKERS 
• RabbitMQ (by VMWARE)! 
• Microsoft's Windows Azure 
Service Bus! 
• Red Hat Enterprise MRG! 
• StormMQ
Lorem Ipsum Dolor 
RABBITMQ Open Source message 
broker / queueing system 
written in Erlang 
implementing AMQP
Who Uses AMQP 
• JPMorgan - 1 billion AMQP messages per day; used in 
dozens of mission critical systems worldwide! 
• VMware - Makes extensive use of RabbitMQ in its 
virtualization products and cloud service! 
• Google! 
• UIDAI, Government of India - the largest online 
identity project in the world aiming to provide each of 
India's 1.2 billion residents with a unique identity 
number! 
• AT&T, Smith Electric Vehicles, Mozilla, RED HAT cloud 
services
INDUSTRIES Telecommunications, Defense, 
Manufacturing, Internet and 
Cloud Computing
Installing 
RABBitMQ 
• MAC OSX - brew install 
rabbitmq ! 
• Windows - download the 
exe
Running It rabbitmq-server
Enabling the admin 
console 
• rabbitmq-plugins enable 
rabbitmq_management! 
! 
• http://http://localhost: 
15672/
How to talk to 
RABBITMQ An AMQP Client. Available in 
most languages.
Ruby clients • Bunny! 
• Ruby AMQP Gem
INSTALLING 
BUNNY 
• gem install bunny ! 
• add to gem file -> gem 
‘bunny’
Lorem Ipsum Dolor 
AMQP-MODEL 
• messages can be anything,! 
plain text, json, bytes, etc.! 
• Publisher and Consumer 
are typically decoupled in 
big apps
Exchanges and 
Exchange Types 
• Direct exchange - specific 
routing key! 
• Fanout exchange - braodcast! 
• Topic exchange - regex style 
routing key! 
• Headers exchange
DIRECT 
EXCHANGE
Lorem Ipsum Dolor 
DIRECT 
EXCHANGE 2
Lorem Ipsum Dolor 
FAN-OUT 
• leaderboard updates or other 
global events! 
• Sport news sites can use score 
updates to mobile clients in near 
real-time! 
• Group chats can distribute 
messages between participants
Lorem Ipsum Dolor 
TOPIC 
EXCHANGE 
• delimeter is dots! 
• * = 1! 
• # = anything
USING BUNNY 
require “bunny”! 
#connect to rabbitmq! 
conn = Bunny.new! 
conn.start! 
#create channel! 
channel = conn.create_channel! 
#create / subscribe to a queue! 
queue = ch.queue(“hello”)! 
exchange = ch.default_exchange! 
#bind queue to an exchange! 
queue.bind(exchange, :routing_key => 
severity) 
exchange.publish("Hello 
World!", :routing_key => queue.name) 
queue.subscribe(:block => true) do | 
delivery_info, properties, body|! 
puts " [x] Received #{body}"! 
! 
# cancel the consumer to exit! 
delivery_info.consumer.cancel! 
end
DEMO 
code: https://github.com/selasiehanson/rabbitmq_presentaion_code.git
FANOUT 
❖ cd pubsub! 
❖ ruby receive_logs.rb > logs_from_rabbit.log! 
❖ ruby receive_logs.rb! 
❖ ruby emit_log.rb! 
❖ ruby emit_log.rb "Hello my peeps"
DIRECT (3 receivers) 
❖ cd ../routing/! 
❖ ruby receive_logs_direct.rb warning error > 
logs_from_rabbit.log! 
❖ ruby receive_logs_direct.rb info warning error! 
❖ ruby receive_logs_direct.rb info warning! 
❖ ruby emit_log_direct.rb error “Message 1”! 
❖ ruby emit_log_direct.rb warning “Message 2”
TOPIC 
❖ cd ../topic/! 
❖ ruby receive_logs_topic.rb "#"! 
❖ ruby receive_logs_topic.rb "kern.*"! 
❖ ruby receive_logs_topic.rb "*.critical"! 
❖ ruby receive_logs_topic.rb "kern.*" "*.critical"! 
❖ ruby emit_log_topic.rb "kern.critical" "A critical kernel 
error"
THE END
RESOURCES 
❖ http://www.amqp.org/! 
❖ http://www.rabbitmq.com/! 
❖ http://www.rabbitmq.com/getstarted.html! 
❖ http://www.rabbitmq.com/tutorials/amqp-concepts.html! 
❖ http://rubybunny.info/! 
❖ http://rubybunny.info/articles/getting_started.html! 
❖ read the bunny docs! 
❖ http://www.rubyinside.com/rabbitmq-a-fast-reliable-queuing-option-for- 
rubyists-1681.html

Messaging with amqp and rabbitmq

  • 1.
    MESSAGING WITH AMQPAND RABBITMQ
  • 2.
    What is AMQP? AMQP (Advanced Message Queuing Protocol) is a networking protocol that enables conforming client applications to communicate with conforming messaging middleware brokers.
  • 3.
    WHAT ARE BROKERS Messaging brokers receive messages from publishers (applications that publish them, also known as producers) and route them to consumers (applications that process them).
  • 4.
    EXAMPLE OF BROKERS • RabbitMQ (by VMWARE)! • Microsoft's Windows Azure Service Bus! • Red Hat Enterprise MRG! • StormMQ
  • 5.
    Lorem Ipsum Dolor RABBITMQ Open Source message broker / queueing system written in Erlang implementing AMQP
  • 6.
    Who Uses AMQP • JPMorgan - 1 billion AMQP messages per day; used in dozens of mission critical systems worldwide! • VMware - Makes extensive use of RabbitMQ in its virtualization products and cloud service! • Google! • UIDAI, Government of India - the largest online identity project in the world aiming to provide each of India's 1.2 billion residents with a unique identity number! • AT&T, Smith Electric Vehicles, Mozilla, RED HAT cloud services
  • 8.
    INDUSTRIES Telecommunications, Defense, Manufacturing, Internet and Cloud Computing
  • 9.
    Installing RABBitMQ •MAC OSX - brew install rabbitmq ! • Windows - download the exe
  • 10.
  • 11.
    Enabling the admin console • rabbitmq-plugins enable rabbitmq_management! ! • http://http://localhost: 15672/
  • 12.
    How to talkto RABBITMQ An AMQP Client. Available in most languages.
  • 13.
    Ruby clients •Bunny! • Ruby AMQP Gem
  • 14.
    INSTALLING BUNNY •gem install bunny ! • add to gem file -> gem ‘bunny’
  • 15.
    Lorem Ipsum Dolor AMQP-MODEL • messages can be anything,! plain text, json, bytes, etc.! • Publisher and Consumer are typically decoupled in big apps
  • 16.
    Exchanges and ExchangeTypes • Direct exchange - specific routing key! • Fanout exchange - braodcast! • Topic exchange - regex style routing key! • Headers exchange
  • 17.
  • 18.
    Lorem Ipsum Dolor DIRECT EXCHANGE 2
  • 19.
    Lorem Ipsum Dolor FAN-OUT • leaderboard updates or other global events! • Sport news sites can use score updates to mobile clients in near real-time! • Group chats can distribute messages between participants
  • 20.
    Lorem Ipsum Dolor TOPIC EXCHANGE • delimeter is dots! • * = 1! • # = anything
  • 21.
    USING BUNNY require“bunny”! #connect to rabbitmq! conn = Bunny.new! conn.start! #create channel! channel = conn.create_channel! #create / subscribe to a queue! queue = ch.queue(“hello”)! exchange = ch.default_exchange! #bind queue to an exchange! queue.bind(exchange, :routing_key => severity) exchange.publish("Hello World!", :routing_key => queue.name) queue.subscribe(:block => true) do | delivery_info, properties, body|! puts " [x] Received #{body}"! ! # cancel the consumer to exit! delivery_info.consumer.cancel! end
  • 22.
  • 23.
    FANOUT ❖ cdpubsub! ❖ ruby receive_logs.rb > logs_from_rabbit.log! ❖ ruby receive_logs.rb! ❖ ruby emit_log.rb! ❖ ruby emit_log.rb "Hello my peeps"
  • 24.
    DIRECT (3 receivers) ❖ cd ../routing/! ❖ ruby receive_logs_direct.rb warning error > logs_from_rabbit.log! ❖ ruby receive_logs_direct.rb info warning error! ❖ ruby receive_logs_direct.rb info warning! ❖ ruby emit_log_direct.rb error “Message 1”! ❖ ruby emit_log_direct.rb warning “Message 2”
  • 25.
    TOPIC ❖ cd../topic/! ❖ ruby receive_logs_topic.rb "#"! ❖ ruby receive_logs_topic.rb "kern.*"! ❖ ruby receive_logs_topic.rb "*.critical"! ❖ ruby receive_logs_topic.rb "kern.*" "*.critical"! ❖ ruby emit_log_topic.rb "kern.critical" "A critical kernel error"
  • 26.
  • 27.
    RESOURCES ❖ http://www.amqp.org/! ❖ http://www.rabbitmq.com/! ❖ http://www.rabbitmq.com/getstarted.html! ❖ http://www.rabbitmq.com/tutorials/amqp-concepts.html! ❖ http://rubybunny.info/! ❖ http://rubybunny.info/articles/getting_started.html! ❖ read the bunny docs! ❖ http://www.rubyinside.com/rabbitmq-a-fast-reliable-queuing-option-for- rubyists-1681.html