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
160
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
110
How to React Appropriately
glenjamin
1
490
Bumping our Stack to PHP 5.5
glenjamin
0
220
Messages queues don't need to be scary.
glenjamin
1
98
Upgrading from PHP 5.3 to 5.5
glenjamin
1
1.2k
Other Decks in Technology
See All in Technology
障害を回避するHttpClient再入門 / Avoiding Failures HttpClient Reintroduction
uskey512
1
370
為什麼我們需要 Observability?
marcustung
0
380
金融システムをモダナイズするためのAmazon Elastic Kubernetes Service(EKS)ノウハウ大全
daitak
0
140
Flutterアプリを⾃然⾔語で操作する
yukisakai1225
0
190
Agent Development Kit によるエージェント開発入門
enakai00
2
250
Azure Developer CLI と Azure Deployment Environment / Azure Developer CLI and Azure Deployment Environment
nnstt1
1
160
Introduction to Bill One Development Engineer
sansan33
PRO
0
240
やさしいClaude Code入門
minorun365
PRO
38
30k
Eight Engineering Unit 紹介資料
sansan33
PRO
0
3.3k
[zh-TW] DevOpsDays Taipei 2025 -- Creating Awesome Change in SmartNews!(machine translation)
martin_lover
1
680
ソフトウェアテストのAI活用_ver1.10
fumisuke
0
250
MCP Clientを活用するための設計と実装上の工夫
yudai00
1
870
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Balancing Empowerment & Direction
lara
1
98
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Automating Front-end Workflow
addyosmani
1370
200k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
52
2.8k
Music & Morning Musume
bryan
47
6.6k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
Art, The Web, and Tiny UX
lynnandtonic
298
21k
Thoughts on Productivity
jonyablonski
69
4.7k
The Cost Of JavaScript in 2023
addyosmani
49
8.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