$30 off During Our Annual Pro Sale. View Details »

phoenix_channels

astapi
September 01, 2016

 phoenix_channels

astapi

September 01, 2016
Tweet

Other Decks in Programming

Transcript

  1. Phoenix Channels junichi kuriyama(@astapi) 2016.08.31 tokyo.ex#5

  2. • junichi kuriyama(@astapi) • ॴଐ • ݩ ͳձࣾ • ࢓ࣄͰ͸Rubyͨ͠ΓElixirͨ͠ΓΠϯϑϥ(AWS)ͯ͠·͢

    • ٳ೔͸Erlangͨ͠ΓElixirͨ͠Γͯ͠·͢
  3. ࿩͢಺༰ • Phoenix ͷ Channels ͱ͍͏ػೳͷ঺հ • ࠾༻ࣄྫ

  4. channels ͱ͸ʁ

  5. WebSocket Ͱେมͳͱ͜Ζ Λ৭ʑ΍ͬͯ͘ΕΔ΍ͭ

  6. • ઀ଓपΓ • connection؅ཧ • pubsub • broadcast௨৴

  7. ϦΞϧλΠϜͳ૒ํ޲௨৴Λ ͍͍ײ͡ʹ΍ΕΔ΍ͭ

  8. େ͖͘3module͋Δ ※ݸਓͷײ૝Ͱ͢

  9. • Transports • Channel • PubSub

  10. Transports • cowboy < - > channel ( message dispatch)

    • encode & decode • phoenix message < -> json • WebSocket & LongPolling ( fall back )
  11. Channel • GenServer • controllerతͳ • transport < - >

    channel • transport͕ݺͿɺcall back ϝιουͷ࣮૷ • Rest API ײ֮ͰϩδοΫʹूதͰ͖Δ
  12. xxx_channel.ex def handle_in(“new_msg”, %{“uid” => uid, “body” => body}, socket)

    do broadcast! socket, “new_msg”, %{uid: uid, body: body} {:noreply, socket} end def handle_in(“create:post”, attrs, socket) do changes = Post.changeset(%Post{}, attrs) if changeset.valid? do Repo.insert!(changeset) {:reply, :ok, socket} else {:reply, :error, socket} end end
  13. PubSub • publish - subscribe • connection process ؅ཧ (

    ets ) • pubsub backend • Pg2 ( default) • Redis • RabbitMQ • Postgres
  14. ࢀߟจݙ Elixir Slack (#phoenix)

  15. ࠾༻ࣄྫ

  16. ࠾༻ࣄྫ

  17. ৄ͘͠͸ͪ͜Β http://logmi.jp/155707

  18. Կ͔Λ͢Δ - ౤ߘ? - profileߋ৽? phoenix server Կ͔͋ͬͨΑɻ ͱɺwebsocketʹ ઀ଓ͍ͯ͠Δ

    Ϣʔβʔʹ௨஌
  19. ·ͱΊ

  20. • channels͸websocketΛ͍͍ײ͡ʹ࢖͑ Δ΍ͭ • channels͸େ͖͘ɺtransports, channel, pubsub ͷ3ͭ • channel

    ͷ࣮૷ʹʢ΄΅ʣूதͰ͖Δ
  21. we are hiring @ • Phoenix ͷ Channels ͱ͍͏ػೳͷ঺հ