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
Message Queues for Everyone
Search
Glen Mailer
March 27, 2014
Technology
1
130
Message Queues for Everyone
An intro to AMQP for Node.js developers
Glen Mailer
March 27, 2014
Tweet
Share
More Decks by Glen Mailer
See All by Glen Mailer
Are you afraid of dependencies?
glenjamin
0
62
How to React Appropriately
glenjamin
1
420
Bumping our Stack to PHP 5.5
glenjamin
0
190
Messages queues don't need to be scary.
glenjamin
1
94
Upgrading from PHP 5.3 to 5.5
glenjamin
1
1.1k
Other Decks in Technology
See All in Technology
開発と事業を繋ぐ!SREのオブザーバビリティ戦略 ~ Developers Summit 2024 Summer ~
leveragestech
0
640
さらに高品質・高速化を目指すAI時代のテスト設計支援と、めざす先 / AI Test Lab vol.1
shift_evolve
0
190
Amazon FSx for NetApp ONTAPのパフォーマンスチューニング要素をまとめてみた #cm_odyssey #devio2024
non97
0
220
フルリモートワークはエンジニアの夢を叶えたか? #cm_odyssey
mamohacy
2
600
Git 研修 Advanced【MIXI 24新卒技術研修】
mixi_engineers
PRO
0
200
AI研修【MIXI 24新卒技術研修】
mixi_engineers
PRO
0
130
頼られるのが大好きな 皆さんへ - 支援相手との期待の合わせ方、突き放し方 -/For_people_who_like_to_be_relied_on
naitosatoshi
1
290
Azure Pipelinesを使用したCICDベースラインアーキテクチャ実践
yuriemori
0
190
Matterport を使ってクラスメソッド各拠点のバーチャルオフィスツアーを作成してみた
wakatsuki
0
160
運用改善、不都合な真実 / 20240722-ssmjp-kaizen
opelab
17
8.4k
AIアシスタントの活用で品質の向上と開発ワークフローのスピードアップ
nagix
1
210
セキュリティ研修 Day1【MIXI 24新卒技術研修】
mixi_engineers
PRO
0
160
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
46
7k
Designing on Purpose - Digital PM Summit 2013
jponch
113
6.6k
The World Runs on Bad Software
bkeepers
PRO
63
11k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
26
2.1k
Agile that works and the tools we love
rasmusluckow
325
20k
Intergalactic Javascript Robots from Outer Space
tanoku
266
26k
What’s in a name? Adding method to the madness
productmarketing
PRO
21
2.9k
YesSQL, Process and Tooling at Scale
rocio
166
14k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
353
29k
Fantastic passwords and where to find them - at NoRuKo
philnash
42
2.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
18
1.2k
Building Effective Engineering Teams - LeadDev
addyosmani
47
2.2k
Transcript
Message queues for everyone An intro workshop to AMQP For
Node.js Developers
AMQP
Advanced Message Queuing Protocol
0.9.1
None
Why?
Job Queue Event Stream Buffered RPC
Job Queue
Producer Consumer
Producer Consumer Producer
Producer Consumer Producer Consumer
Producer Consumer Producer Consumer
Exchange In Queue Out
Slow Operations Expensive Operations Brittle Operations
Producer c = create_channel q = c.queue("task") x = c.default_exchange
x.publish( "job1", "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(ack = TRUE, worker) worker
= fn(body, headers, info, m) { // do work m.acknowledge() }
Publishing Options Mandatory Will error if not queued 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
Messages Routing Key
Exchanges Fanout: all queues Direct: matching key Topic: key patterns
Exchange | Binding | Queue
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
Smooth out Spikes Transparently scale Deferred Response
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" })
Admin Interface Demo
Why not just use … ?
Redis pub/sub (Resque etc)
Beanstalkd
JMS Stomp
MQTT
ØMQ
Node.js Quickstart
npm install amqp
var amqp = require('amqp') var conn = amqp.createConnection( {
url: 'amqp://un:pw@host:5672/vhost' }, { reconnect: false } ) conn.on('ready', function() { // Do stuff })
var opts = { noDeclare: true } conn.queue(name, opts, function(q)
{ q.subscribe( { ack: true, prefetch: 1 }, onMessage ) }) function onMessage(body, meta, info, msg) { // do some stuff msg.acknowledge() }
var opts = { type: 'topic', noDeclare: true } conn.exchange(name,
opts, function(x) { x.publish('key', 'body', { contentType: 'text/json' }) })
Questions?
Lets go! http://amqp-nodejs.herokuapp.com https://addons.heroku.com/marketplace/rabbitmq-bigwig
@glenathan