Upgrade to Pro — share decks privately, control downloads, hide ads and more …

phoenix_channels

astapi
September 01, 2016

 phoenix_channels

astapi

September 01, 2016
Tweet

Other Decks in Programming

Transcript

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

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

    channel • transport͕ݺͿɺcall back ϝιουͷ࣮૷ • Rest API ײ֮ͰϩδοΫʹूதͰ͖Δ
  3. 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
  4. PubSub • publish - subscribe • connection process ؅ཧ (

    ets ) • pubsub backend • Pg2 ( default) • Redis • RabbitMQ • Postgres