Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Cowboy - RabbitMQ and websockets
Search
Wade Mealing
September 17, 2013
Technology
3
1.5k
Cowboy - RabbitMQ and websockets
A quick overview on how to plug together some buzzword enabled tech for your enjoyment.
Wade Mealing
September 17, 2013
Tweet
Share
Other Decks in Technology
See All in Technology
Connection-based OAuthから学ぶOAuth for AI Agents
flatt_security
0
370
『君の名は』と聞く君の名は。 / Your name, you who asks for mine.
nttcom
1
120
NIKKEI Tech Talk #41: セキュア・バイ・デザインからクラウド管理を考える
sekido
PRO
0
220
202512_AIoT.pdf
iotcomjpadmin
0
150
MariaDB Connector/C のcaching_sha2_passwordプラグインの仕様について
boro1234
0
1k
「図面」から「法則」へ 〜メタ視点で読み解く現代のソフトウェアアーキテクチャ〜
scova0731
0
510
会社紹介資料 / Sansan Company Profile
sansan33
PRO
11
390k
TED_modeki_共創ラボ_20251203.pdf
iotcomjpadmin
0
150
ESXi のAIOps だ!2025冬
unnowataru
0
370
[Neurogica] 採用ポジション/ Recruitment Position
neurogica
1
130
AI駆動開発ライフサイクル(AI-DLC)の始め方
ryansbcho79
0
190
Identity Management for Agentic AI 解説
fujie
0
480
Featured
See All Featured
Facilitating Awesome Meetings
lara
57
6.7k
Paper Plane
katiecoart
PRO
0
44k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
92
Balancing Empowerment & Direction
lara
5
820
How GitHub (no longer) Works
holman
316
140k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.1k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
710
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Discover your Explorer Soul
emna__ayadi
2
1k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
Tell your own story through comics
letsgokoyo
0
770
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
Transcript
Erlang + Message Queue + HTML 5 Tech
= Over-engineered Chat Server
What Cowboy ? https://github.com/extend/cowboy Small, fast modular web server written
in erlang.
What Gen Bunny https://github.com/mochi/gen_bunny RabbitMQ client library for simple pubsub
in erlang.
What Websocket ? https://www.websocket.org/ Bi-directional web communication mechanism.
Over Architecturing You want it. I deliver !
Server Moving parts Cowboy Gen Bunny Browser
Client Moving parts Cowboy Gen Bunny Browser
Websockets Technical Detour
Client Moving parts Browser Browser Server HTTP Port 80 Port
80
Client Moving parts Browser Browser Server WS Upgrade Upgrade Port
80 Port 80
WHY ? WORKS WITH EXISTING PROXIES
Client JS Data is live chat stream
JS Connection wsUrl = "ws://server:8081/websocket"; websocket = new WebSocket(wsUrl);
Websocket Setup websocket = new WebSocket(wsURL); websocket.onopen = ... websocket.onmessage
= function(evt){ onMessage(e) }; websocket.onerror = ...
onMessage Handler function onMessage(e) { Msg = '<p>' + txt
+ '</p>' $('#output').prepend(Msg); };
Smooth Yeah
Server Side Server WS
Cowboy What comes to mind ?
Kid Rock
Fresh Leather
Pretty Lil' web server
Cowboy Routes, REST, middleware, web sockets and more.
Cowboy follows OTP principals.
Cowboy WS Required Callbacks init websocket_init websocket_handle websocket_info websocket_terminate
Cowboy WS init Upgrades from http → web socket
Cowboy WS init({tcp, http}, _Req, _Opts) → {upgrade,protocol,cowboy_websocket}.
Cowboy WS websocket_init Run on each connection.
Cowboy WS websocket_init(_Name, Req, _Opts) → Pid = consumer:start_link(), {ok,
Req, #state{pid=Pid}}.
Cowboy WS websocket_handle Recv data from client, optionally return data.
Cowboy WS websocket_handle(Data, Req, State) → {text, Msg} = Data,
{reply, {text, << "recv: ", Msg/binary >>}, Req, State};
Cowboy WS websocket_info Live Push data to client
Cowboy WS websocket_info(Data, Req, State) → {reply, {text, Data}, Req,State};
Sending to RabbitMQ RabbitMQ websocket_handle
Recv from RabbitMQ RabbitMQ websocket_info gen_bunny CONSUMER
Message Queues gen bunny
gen_bunny follows OTP principals.
callbacks Required: • handle_message • init • handle_call • handle_cast
• handle_info • terminate
callbacks handle_message Handle messages from the message subscribed message queue.
callbacks handle_message(Msg, State) → NewState = act_on_msg(Msg,State) {noreply, NewState};
MQ perspective Exchange Exchange “Fanout” M S G M S
G M S G M S G M S G M S G M S G M S G M S G M S G M S G M S G
Live demo Wireless Network: Name: rabbit Password: carrot VISIT: http://10.1.1.1:8081/
Benchmarking Method: Connect to Websocket Wait for signal. Send 100
messages. Receive all messages
Benchmarking Results: (Didn't get this done in time, sorry) 0.5
1 1.5 2 2.5 3 3.5 4 4.5 0 2 4 6 8 10 12 Column 1 Column 2 Column 3
Source Code github.com/wmealing/ bunny-cowboy-websocket