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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
590
Bumping our Stack to PHP 5.5
glenjamin
0
280
Message Queues for Everyone
glenjamin
1
220
Upgrading from PHP 5.3 to 5.5
glenjamin
1
1.3k
Other Decks in Technology
See All in Technology
ハーレムエンジニアリング
kazuma777777
0
160
Goでデータパイプラインを作ろう
sansantech
PRO
1
450
20分でわかるセキュアAPI
nwiizo
2
270
【CEDEC2026】次世代デジタルカードゲームのサーバー設計と運用 〜『Shadowverse: Worlds Beyond』の舞台裏~
cygames
PRO
1
1.3k
MIRU 2026 チュートリアル
keisuke198619
0
910
My broken English still works: speaking at global OSS events
naruoga
0
100
Master Dataグループ紹介資料
sansan33
PRO
1
4.8k
ボトムアップ文化が強い組織で セキュリティをどう根付かせていくかの現在進行形の話 / Making Security Stick in a Bottom-Up Organization
yamaguchitk333
0
220
AIエージェントを前提としたプラットフォーム エンジニアリング:GKEで作るAgent-Ready Golden Path
legalontechnologies
PRO
2
240
グローバル基準のSREは、運用現場でどう機能したか:成熟度アセスメントの実践 / SRE NEXT 2026
sorawatanabe
0
230
今こそ聞きたいソフトウェア設計 ドメイン駆動設計再入門
masuda220
PRO
17
7.3k
関東Kaggler会発表資料
takoi
1
230
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
55
12k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Limits of Empathy - UXLibs8
cassininazir
1
600
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
73
41k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
490
A Modern Web Designer's Workflow
chriscoyier
698
190k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
0
470
How STYLIGHT went responsive
nonsquared
100
6.2k
ラッコキーワード サービス紹介資料
rakko
1
4.3M
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")