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
150
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
Cursorをチョッパヤインタビューライターにチューニングする方法 / how to tuning cursor for interview write
shuzon
2
270
既存の開発資産を活かしながら、 《新規開発コスト抑制》と《開発体験向上》 を両立する拡張アーキテクチャ事例
kubell_hr
0
280
"発信文化"をどうやって計測する?技術広報のKPI探索記/How do we measure communication culture?
bitkey
4
350
Cursorを全エンジニアに配布 その先に見据えるAI駆動開発の未来 / 2025-05-13-forkwell-ai-study-1-cursor-at-loglass
itohiro73
2
760
インラインRBSコメントに鯛pe checkersもニッコリ
sansantech
PRO
1
190
Software Delivery Observability CI・CD , DORA metrics も Datadog で可視化しよう / datadog-ci-cd-observability
parupappa2929
0
160
テスト設計、逆から読むとおもしろい──仕様にない“望ましさ”の逆設計
mhlyc
0
110
計測による継続的なCI/CDの改善
sansantech
PRO
7
2.2k
人間性を捧げる生成AI時代の技術選定
yo4raw
1
920
Next.jsと状態管理のプラクティス
uhyo
6
2.4k
スイッチのBMC、つかってますか?
sonic
0
400
UIパフォーマンス最適化: AIを活用して100倍の速度向上を実現した事例
kinocoboy2
1
630
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
29
9.5k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
Balancing Empowerment & Direction
lara
0
43
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
32
2.3k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
Mobile First: as difficult as doing things right
swwweet
223
9.6k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
179
53k
Building Applications with DynamoDB
mza
94
6.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
A Modern Web Designer's Workflow
chriscoyier
693
190k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
StorybookのUI Testing Handbookを読んだ
zakiyama
30
5.7k
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