View Source Polyn (Polyn v0.6.3)

Polyn is a dead simple service framework designed to be language agnostic while providing a simple, yet powerful, abstraction layer for building reactive events based services.

Link to this section Summary

Types

Options you can pass to most Polyn module functions

Options for publishing events. See Gnat.pub/4 for more info

Options for publishing events. See Gnat.request/4 for more info

Functions

Publish an event to the message bus. Will validate the data against an existing schema added by Polyn CLI.

Reply to an event you've subscribed to that included a reply_to option.

Issue a request in a psuedo-synchronous fashion. Requests still require an event be defined in the schema store. The event you send and receive will both be validated

Link to this section Types

@type polyn_options() :: {:store_name, binary()} | {:source, binary()}

Options you can pass to most Polyn module functions

  • :source - The source of the event. By default will be the domain combined with the source_root
@type pub_options() ::
  polyn_options() | {:headers, Gnat.headers()} | {:reply_to, binary()}

Options for publishing events. See Gnat.pub/4 for more info

  • :headers - Headers to include in the message
  • :reply_to - Subject to send a response to
@type req_options() ::
  polyn_options()
  | {:headers, Gnat.headers()}
  | {:receive_timeout, non_neg_integer()}

Options for publishing events. See Gnat.request/4 for more info

  • :headers - Headers to include in the message
  • :receive_timeout - How long to wait for a response

Link to this section Functions

Link to this function

pub(conn, event_type, data, opts \\ [])

View Source
@spec pub(
  conn :: Gnat.t(),
  event_type :: binary(),
  data :: any(),
  opts :: [pub_options()]
) :: :ok

Publish an event to the message bus. Will validate the data against an existing schema added by Polyn CLI.

options

Options

  • :source - The source of the event. By default will be the domain combined with the source_root
  • See Gnat.pub/4 for other options

examples

Examples

iex>Polyn.pub(:gnat, "user.created.v1", %{name: "Mary"})
:ok
iex>Polyn.pub(:gnat, "user.created.v1", %{name: "Mary"}, source: "admin")
:ok
Link to this function

reply(conn, reply_to, event_type, data, opts \\ [])

View Source
@spec reply(
  conn :: Gnat.t(),
  reply_to :: binary(),
  event_type :: binary(),
  data :: any(),
  opts :: [pub_options()]
) :: :ok

Reply to an event you've subscribed to that included a reply_to option.

options

Options

  • :source - The source of the event. By default will be the domain combined with the source_root
  • See Gnat.pub/4 for other options

examples

Examples

iex>Polyn.reply(:gnat, "INBOX.me", "user.created.v1", %{name: "Mary"})
:ok
iex>Polyn.reply(:gnat, "INBOX.me", "user.created.v1", %{name: "Mary"}, source: "admin")
:ok
Link to this function

request(conn, event_type, data, opts \\ [])

View Source
@spec request(
  conn :: Gnat.t(),
  event_type :: binary(),
  data :: any(),
  opts :: [req_options()]
) :: {:ok, Gnat.message()} | {:error, :timeout}

Issue a request in a psuedo-synchronous fashion. Requests still require an event be defined in the schema store. The event you send and receive will both be validated

options

Options

  • :source - The source of the event. By default will be the domain combined with the source_root
  • See Gnat.request/4 for other options

examples

Examples

iex>Polyn.request(:gnat, "user.created.v1", %{name: "Mary"})
{:ok, %{body: %Event{}}}
iex>Polyn.request(:gnat, "user.created.v1", %{name: "Mary"}, source: "admin")
{:ok, %{body: %Event{}}}