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
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
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
37
14k
赤煉瓦倉庫勉強会「Databricksを選んだ理由と、絶賛真っ只中のデータ基盤移行体験記」
ivry_presentationmaterials
2
350
React開発にStorybookとCopilotを導入して、爆速でUIを編集・確認する方法
yu_kod
1
270
生まれ変わった AWS Security Hub (Preview) を紹介 #reInforce_osaka / reInforce New Security Hub
masahirokawahara
0
460
Zephyr RTOSを使った開発コンペに参加した件
iotengineer22
1
220
Tokyo_reInforce_2025_recap_iam_access_analyzer
hiashisan
0
180
敢えて生成AIを使わないマネジメント業務
kzkmaeda
2
430
OPENLOGI Company Profile
hr01
0
67k
Connect 100+を支える技術
kanyamaguc
0
200
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
2
7.7k
MobileActOsaka_250704.pdf
akaitadaaki
0
120
Understanding_Thread_Tuning_for_Inference_Servers_of_Deep_Models.pdf
lycorptech_jp
PRO
0
180
Featured
See All Featured
A designer walks into a library…
pauljervisheath
207
24k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Building an army of robots
kneath
306
45k
KATA
mclloyd
30
14k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Building a Modern Day E-commerce SEO Strategy
aleyda
42
7.4k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
Building Adaptive Systems
keathley
43
2.7k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
820
Visualization
eitanlees
146
16k
Scaling GitHub
holman
459
140k
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