Talk:Event Platform/EventStreams

From Wikitech
Jump to navigation Jump to search

Elixir client

I wrote a streaming parser for Elixir, but wasn't sure whether I should add it to the "examples" section of this page, or perhaps there's a longer list of Wiki SSE clients somewhere else?

Example code depending on the wiki_elixir library:

defmodule EchoSSE do
  def start(:normal, []) do
    WikiSSE.start_link(&EchoSSE.echo_event/1)
  end

  @doc """
  Example callback prints a summary of each message.
  """
  def echo_event(message) do
    data = Poison.decode!(message.data)
    case data["type"] do
      "edit" ->
        IO.puts ~s(#{data["meta"]["dt"]}: #{data["wiki"]} #{data["title"]} edited by #{data["user"]})
      _ ->
        IO.puts ~s(#{data["meta"]["dt"]}: #{data["type"]} event: #{message.data})
    end
  end
end

Awight (talk) 18:58, 9 March 2019 (UTC)