View Source Wiki.EventStreams (mediawiki_client v0.4.0)

This module reads from an infinite stream of server-sent events annotating actions such as editing or patrolling, as they happen on Wikimedia projects.

For more about the public wiki streams and their format, see EventStreams on Wikitech

examples

Examples

Start reading the page creation feed, and expose as a GenStage.stream:

Wiki.EventStreams.start_link(streams: "page-create")
Wiki.EventStreams.stream()
|> Stream.take(6)
|> Enum.to_list

Combine multiple feeds,

Wiki.EventStreams.start_link(streams: ["revision-create", "revision-score"])
Wiki.EventStreams.stream()
|> Stream.take(6)
|> Enum.to_list

todo

TODO

  • Currently only a single supervisor tree is supported, so calling applications can only read from one stream.
  • Track the restart ID, disconnect from the feed at some maximum queue size. Reconnect as demand resumes. Application-lifetime or permanent storage for the restart ID tracking, for consumers that need an at-least-once guarantee.

Link to this section Summary

Types

  • :adapter - Override the HTTP adapter.
  • :endpoint - Override the default endpoint URL.
  • :stream_to - Optional application which will receive the events, otherwise they go to the process starting the EventStream.
  • :streams - One or more atoms with the stream names to subscribe to.
  • :user_agent - Custom user-agent header string

Functions

Returns a specification to start this module under a supervisor.

Start a supervisor tree to receive and relay server-side events.

Capture subscribed events and relay them as a Stream.

Link to this section Types

@type client_option() ::
  {:adapter, module()}
  | {:endpoint, binary()}
  | {:stream_to, GenServer.server()}
  | {:streams, atom() | [atom()]}
  | {:user_agent, binary()}
@type client_options() :: [client_option()]
  • :adapter - Override the HTTP adapter.
  • :endpoint - Override the default endpoint URL.
  • :stream_to - Optional application which will receive the events, otherwise they go to the process starting the EventStream.
  • :streams - One or more atoms with the stream names to subscribe to.
  • :user_agent - Custom user-agent header string

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec start_link(client_options()) :: GenServer.on_start()

Start a supervisor tree to receive and relay server-side events.

arguments

Arguments

  • options - Keyword list,
    • {:adapter, module} - Override HTTPoison adapter.
    • {:endpoint, url} - Override default endpoint.
    • {:send_to, pid | module} - Instead of using the built-in streaming relay, send the events directly to your own process.

    • {:streams, atom | [atom]} - Select which streams to listen to. An updated list can be found here. Required.

@spec stream(client_options()) :: Enumerable.t()

Capture subscribed events and relay them as a Stream.