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
1
94
Messages queues don't need to be scary.
An introduction tutorial to AMQP with RabbitMQ and Ruby.
Glen Mailer
October 14, 2013
Tweet
Share
More Decks by Glen Mailer
See All by Glen Mailer
Are you afraid of dependencies?
glenjamin
0
78
How to React Appropriately
glenjamin
1
450
Bumping our Stack to PHP 5.5
glenjamin
0
200
Message Queues for Everyone
glenjamin
1
130
Upgrading from PHP 5.3 to 5.5
glenjamin
1
1.1k
Other Decks in Technology
See All in Technology
Storage Browser for Amazon S3
miu_crescent
1
130
NW-JAWS #14 re:Invent 2024(予選落ち含)で 発表された推しアップデートについて
nagisa53
0
250
フロントエンド設計にモブ設計を導入してみた / 20241212_cloudsign_TechFrontMeetup
bengo4com
0
1.9k
株式会社ログラス − エンジニア向け会社説明資料 / Loglass Comapany Deck for Engineer
loglass2019
3
31k
[Ruby] Develop a Morse Code Learning Gem & Beep from Strings
oguressive
1
150
KubeCon NA 2024 Recap: How to Move from Ingress to Gateway API with Minimal Hassle
ysakotch
0
200
20241220_S3 tablesの使い方を検証してみた
handy
3
320
ずっと昔に Star をつけたはずの思い出せない GitHub リポジトリを見つけたい!
rokuosan
0
150
PHPからGoへのマイグレーション for DMMアフィリエイト
yabakokobayashi
1
160
Snowflake女子会#3 Snowpipeの良さを5分で語るよ
lana2548
0
220
2024年にチャレンジしたことを振り返るぞ
mitchan
0
130
サービスでLLMを採用したばっかりに振り回され続けたこの一年のあれやこれや
segavvy
2
380
Featured
See All Featured
Code Reviewing Like a Champion
maltzj
520
39k
What's in a price? How to price your products and services
michaelherold
243
12k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
YesSQL, Process and Tooling at Scale
rocio
169
14k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
Agile that works and the tools we love
rasmusluckow
328
21k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Language of Interfaces
destraynor
154
24k
Side Projects
sachag
452
42k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
Producing Creativity
orderedlist
PRO
341
39k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
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")