Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Messages queues don't need to be scary.
Search
Glen Mailer
October 14, 2013
Technology
140
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Messages queues don't need to be scary.
An introduction tutorial to AMQP with RabbitMQ and Ruby.
Glen Mailer
October 14, 2013
More Decks by Glen Mailer
See All by Glen Mailer
Are you afraid of dependencies?
glenjamin
0
160
How to React Appropriately
glenjamin
1
600
Bumping our Stack to PHP 5.5
glenjamin
0
280
Message Queues for Everyone
glenjamin
1
230
Upgrading from PHP 5.3 to 5.5
glenjamin
1
1.3k
Other Decks in Technology
See All in Technology
全員がプロダクトへ向き合う組織を持続成長させるために——組織づくりのフライホイールと4象限 / The Flywheel Model and Four Quadrants for Organizational Design
hiro_torii
1
140
Claude Codeの体系的な理解と知識のフック
oikon48
10
6.5k
魔法少女がClaude Codeを監視する / ccportal-deck
noriyukitakei
3
120
スクラムで身についていた動き方を、XPで捉え直してみた
codmoninc
0
120
人気商品が「ちゃんと買える」をつくる ー ECの負荷改善
ykagano
1
190
Bill One 開発エンジニア 紹介資料
sansan33
PRO
7
20k
Azure App Service / Container Apps の組み込み認証
kuniteru
0
140
Introduction to Sansan Meishi Maker Development Engineer
sansan33
PRO
0
470
研究開発部の紹介 / Sansan R&D Profile
sansan33
PRO
4
25k
Continuous Delivery! It is not what you think it is
tdpauw
0
140
「重なり」は迎える側がつくる ― 人もAIエージェントも歓迎するプロダクトエンジニアリング ―
go0517go
PRO
0
110
KPIだけでは評価できないプロダクトが考えるべき Evalsという第二の評価系 / Beyond KPIs: Evals as a Second Evaluation Framework for Products #PdEConf
aki_iinuma
0
760
Featured
See All Featured
Paper Plane (Part 1)
katiecoart
PRO
1
10k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
390
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.9k
The agentic SEO stack - context over prompts
schlessera
0
880
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
570
The Cult of Friendly URLs
andyhume
79
7k
4 Signs Your Business is Dying
shpigford
187
23k
The browser strikes back
jonoalderson
0
1.6k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Transcript
Message queues don't need to be scary An intro workshop
to AMQP
AMQP
Advanced Message Queuing Protocol
None
Why?
Job Queue Event Stream Buffered RPC
Job Queue
Producer Consumer
Producer Consumer Producer
Producer Consumer Producer Consumer
Producer Consumer Producer Consumer
Slow Operations Expensive Operations Brittle Operations
Producer c = create_channel q = c.queue("task") x = c.default_exchange
x.publish( "task", "payload" ) Consumer c = create_channel q = c.queue("task") q.subscribe(worker) worker = fn(*message) { // do stuff }
Acknowledging Messages q = c.queue("task") q.subscribe(worker, ack = TRUE) worker
= fn(info, metadata, body) { // do work c.acknowledge(info.delivery_tag) }
Publishing Options Mandatory Will error if not queued Immediate Will
error if no consumer available Confirm Server acknowledges receipt
Queue Declare Options Passive Don't create, get reference to existing
queue Durable Queue still exists after a broker restart
Event Stream
Producer Consumer Producer Consumer Consumer Consumer Producer
Topic Exchange routing.key Exact match routing.*.key routing.#.key Wildcard matching routing.key
routing.a.key routing.b.key routing.a.b.key
(soft) Real-time updates User notifications Work distribution
Binding a Queue x = c.exchange("activity”) q = c.queue("alert") q.bind(x,
"balance.*") q.bind(x, "transfer.out") x.publish("balance.low") x.publish("transfer.in") x.publish("transfer.out")
Queue Declare Options Exclusive Only one consumer on this queue
at any time Auto Delete Queue is deleted after consumer disconnects
Simulator Demo
Buffered RPC
Producer Consumer
Message Header Reply To Correlation ID
Reply To reply = c.queue("abcdef") x.publish("request", :headers => { :replyTo
=> "abcdef" }) reply.subscribe(handleResponse)
Correlation ID x.publish("request1", :headers => { :replyTo => "abcdef", :correlationID
=> "request1" }) x.publish("request2", :headers => { :replyTo => "abcdef", :correlationID => "request2" })
Smooth out Spikes Transparently scale Deferred Response
Why not just use … ?
Delayed Job Resque / Sidekiq Beanstalkd
JMS Stomp MQTT
ØMQ
Ruby Quickstart
gem install bunny
require 'bunny' url = 'amqp://un:pw@host:5672/vhost' conn = Bunny.new(url) conn.start
ch = conn.create_channel ch.prefetch 1
declare_options = {:no_declare => true} q = ch.queue(name, options)
options = {:block => true, :ack => true} q.subscribe(options) do |info, meta, body| # do stuff ch.ack(info.delivery_tag) end
declare_options = {:no_declare => true} x = ch.topic("name", declare_options)
x.publish("message", :routing_key => "key")