Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Guide to build a realtime application using Pho...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Takayuki Matsubara
October 31, 2014
Programming
2.4k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Guide to build a realtime application using Phoenix on Heroku
#m3dev M3 Tech Talk #32
Guide to build a realtime application using Phoenix on Heroku
Takayuki Matsubara
October 31, 2014
More Decks by Takayuki Matsubara
See All by Takayuki Matsubara
Rails Web Development with AWS Lambda
ma2gedev
0
360
Coding Challenge Advent of Code 2019
ma2gedev
0
170
Developer Experience in GraphQL Schema-first Development
ma2gedev
0
2.4k
Dependency Inversion Principle in Keyboard Firmware
ma2gedev
0
570
OSSの歩き方 / Walking with OSS
ma2gedev
10
2.7k
GraphQL 開発で必要になったこと / What we needed for GraphQL development
ma2gedev
0
1.3k
キーボードをカスタムしてプログラミング環境を良くした話 / Improved programming environment with customizing keybords
ma2gedev
0
1.4k
Translating "Erlang in Anger" with Erlang & Elixir community members
ma2gedev
0
3k
Dive into Elixir v1.6 Code Formatter
ma2gedev
1
210
Other Decks in Programming
See All in Programming
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
480
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
3
350
XP祭りでしか伝わらないフリップネタ #xpjug
murabayashi
0
150
Webの地図
yosuke_furukawa
PRO
6
4.6k
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
180
20260914 AIエージェント時代のPlatform Engineering LLM基盤とプロダクトの責務境界線
kanfab1
7
2.1k
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
430
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
130
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
280
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
3
550
Java 27新機能 / Java 27 new features
kishida
2
150
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
140
Featured
See All Featured
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
520
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
230
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
240
Agile that works and the tools we love
rasmusluckow
331
22k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Balancing Empowerment & Direction
lara
6
1.3k
Skip the Path - Find Your Career Trail
mkilby
1
230
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
KATA
mclloyd
PRO
35
15k
Transcript
Guide to build a realtime application using Phoenix on Heroku
Self introduction • ma2ge @Twitter • ma2gedev @GitHub
Requirement • Erlang 17.0+ • Elixir v1.0.1+
Phoenix Framework Web application framework for Elixir I've experienced that
Rails with Realtime feature
Setup a Phoenix environment $ git clone https://github.com/phoenixframework/phoenix.git # $
git checkout v0.4.1 $ cd phoenix $ mix do deps.get, compile ! v0.5.0 does not work on Heroku choose v0.4.1 or edge
Create a Phoenix application $ mix phoenix.new phoenix_sample ../phoenix_sample $
cd ../phoenix_sample $ git init $ git add . $ git commit -m 'initial commit'
Running on local $ mix do deps.get, compile $ mix
phoenix.start • do not forget to commit $ git add . $ git commit -m 'running on local'
Setup for Heroku $ Heroku create --buildpack \ "https://github.com/HashNuke/heroku-buildpack-elixir.git"
Create 2 files need for Heroku
elixir_buildpack.config # Erlang version erlang_version=17.2 # Elixir version elixir_version=1.0.1 #
Always rebuild from scratch on every deploy? always_rebuild=false # Export heroku config vars # config_vars_to_export=(DATABASE_URL)
Procfile web: mix phoenix.start
Running on Heroku $ git add -u $ git commit
-m 'configuration for heroku' $ git push heroku master $ heroku open
Implement chat with websocket
Phoenix part • Create Channel • Mount Socket and register
Channel
Create Channel web/channels/chat.ex defmodule PhoenixSample.Chat do use Phoenix.Channel def join(socket,
"chat", message) do {:ok, socket} end def event(socket, "message", data) do IO.puts data["message"] broadcast socket, "broadcast_message", %{message: data["message"]} socket end end
Mount Socket and register Channel add the following line to
web/ router.ex use Phoenix.Router.Socket, mount: "/ws" channel "channel", PhoenixSample.Chat
Html and JS side • Include some js files •
Add message box • Write some js codes
Include some js files web/templates/layout/ application.html.eex • Need to download
jquery <script src="/js/jquery.js" type="text/javascript"></script> <script src="/js/phoenix.js" type="text/javascript"></script> <script src="/js/application.js" type="text/javascript"></script>
Add message box web/templates/page/ index.html.eex <div class="row"> <input type="text" id="message-box"
placeholder="any comments?"/> <div id="all-messages"></div> </div>
Write some js codes priv/static/js/application.js $(function() { var socket =
new Phoenix.Socket("/ws"); var $messageBox = $("#message-box"); var $allMessages = $("#all-messages"); socket.join("channel", "chat", {}, function(channel) { $messageBox.keypress(function(e) { if (e.which === 13) { e.preventDefault(); channel.send("message", { message: $messageBox.val() }); $messageBox.val(""); } }); channel.on("broadcast_message", function(data) { console.log("message: " + data['message']); $allMessages.prepend('<p>' + data['message'] + '</p>'); }); }); });
Demo http://goo.gl/dDDwXK
See Also • code • https://github.com/ma2gedev/ phoenix_sample • Phoenix •
https://github.com/phoenixframework/ phoenix
See Also • Deploy Phoenix Application to Heroku • http://learnelixir.com/blog/2014/10/15/
deploy-phonenix-application-to-heroku- server/ • Phoenix Λ heroku Ͱಈ͔͢ • http://qiita.com/ma2ge/items/ cfe17e02f593bb55b084
See Also • Elixir ͷΠϯετʔϧ&Ξοϓσʔτ on Mac • http://qiita.com/ma2ge/items/ e8ad02d604a9c05cb6f6
Enjoy Elixir and Phoenix life