Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov

73 Aufrufe

Veröffentlicht am

Elixir Club 10
March 17, 2018
Kyiv

Veröffentlicht in: Geräte & Hardware
  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov

  1. 1. Александр Хохлов @nots_io Phoenix and beyond: Things we do with Elixir
  2. 2. Founder at Nots.io http://nots.io
  3. 3. Why this talk?
  4. 4. In the beginning…
  5. 5. Phoenix: Web Sockets, HAML, SASS
  6. 6. Guardian, Arc, ex_aws, Swoosh, ueberauth/ueberauth_github
  7. 7. RethinkDB rethinkdb_changefeed postgrex
  8. 8. https://github.com/h4cc/ awesome-elixir
  9. 9. http://obolinx.com/resources/?p=1837
  10. 10. Erlang/Elixir port to Java process with JInterface
  11. 11. https://www.safaribooksonline.com/library/view/erlang-programming/9780596803940/ch16s05.html
  12. 12. def init(_params) do 
 cd = “#{:code.priv_dir(:your_app)}" 
 cmd = "java -jar package.jar" 
 port = Port.open({:spawn,cmd}, [:binary, :use_stdio, packet: 4, cd: cd]) 
 true = Port.connect(port, self()) 
 {:ok,port} 
 end Port.command(port, :erlang.term_to_binary(data)) def handle_info({port,{:data,b}}, port) do 
 data = :erlang.binary_to_term(b) 
 end
  13. 13. Postgrex.Notifications + GenServer
  14. 14. PLPGSQL: PERFORM pg_notify(‘invitations_changes’, payload) Elixir: {:ok, pid} = Postgrex.Notifications.start_link(config) Postgrex.Notifications.listen(pid, "invitations_changes") 
 
 def handle_info({:notification, _pid, _ref, "invitations_changes", payload}, state) do … end
  15. 15. API: HTTP API with Poison & HTTPoison
  16. 16. HTTPoison.put(url, Poison.encode!(data)) 
 HTTPoison.get(url) 
 HTTPoison.post(url, Poison.encode!(data))) 
 case resp do 
 {:ok, %HTTPoison.Response{status_code: 200, body: body}}-> {:ok, body |> Poison.decode!} 
 {:ok, %HTTPoison.Response{status_code: 404}} -> {:error, :not_found} 
 {:ok, %HTTPoison.Response{body: body}} -> {:error, body |> Poison.decode!} 
 {:error, %HTTPoison.Error{reason: reason}} -> {:error, reason} 
 end 

  17. 17. API: Socket API with gen_tcp
  18. 18. # receive tcp packet as message 
 {:ok, socket} = :gen_tcp.connect('localhost', port, [:binary, active: true]) 
 def handle_info({:tcp, _socket, msg}, state) do ... end 
 
 # receive tcp packet with recv 
 :inet.setopts(socket, active: false) 
 :ok = :gen_tcp.send(socket, data) 
 {:ok, <<_msg_len :: binary - size(16), msg :: binary>>} = :gen_tcp.recv(socket, 0, 2000) 

  19. 19. Concurrent tasks
  20. 20. results = notes 
 |> Task.async_stream(__MODULE__, :update, [some, params], max_concurrency: 20) 
 |> Enum.to_list 
 |> Keyword.get(:ok) 
 
 def update(note, some, params) do ... end 

  21. 21. point@nots.io http://nots.io http://blog.nots.io @nots_io facebook.com/nots.io

×