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
500
Bumping our Stack to PHP 5.5
glenjamin
0
230
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
Observability infrastructure behind the trillion-messages scale Kafka platform
lycorptech_jp
PRO
0
140
Delegating the chores of authenticating users to Keycloak
ahus1
0
120
20250625 Snowflake Summit 2025活用事例 レポート / Nowcast Snowflake Summit 2025 Case Study Report
kkuv
1
310
Amazon ECS & AWS Fargate 運用アーキテクチャ2025 / Amazon ECS and AWS Fargate Ops Architecture 2025
iselegant
16
5.5k
Liquid Glass革新とSwiftUI/UIKit進化
fumiyasac0921
0
210
AIのAIによるAIのための出力評価と改善
chocoyama
2
550
How Community Opened Global Doors
hiroramos4
PRO
1
120
本が全く読めなかった過去の自分へ
genshun9
0
290
CI/CD/IaC 久々に0から環境を作ったらこうなりました
kaz29
1
170
Navigation3でViewModelにデータを渡す方法
mikanichinose
0
220
250627 関西Ruby会議08 前夜祭 RejectKaigi「DJ on Ruby Ver.0.1」
msykd
PRO
2
270
BrainPadプログラミングコンテスト記念LT会2025_社内イベント&問題解説
brainpadpr
1
160
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
53
7.7k
Building Applications with DynamoDB
mza
95
6.5k
Bash Introduction
62gerente
614
210k
The World Runs on Bad Software
bkeepers
PRO
69
11k
A better future with KSS
kneath
239
17k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
20k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
Imperfection Machines: The Place of Print at Facebook
scottboms
267
13k
What's in a price? How to price your products and services
michaelherold
246
12k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
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