View Source Polyn.Subscriber behaviour (Polyn v0.3.0)

A GenServer wrapper to use when working with vanilla NATS subscriptions outside of JetStream. This process will hang around and listen for messages to come in and then trigger a handle_message/3 callback

defmodule MySubscriber do
  use Polyn.Subscriber

  def start_link(init_args) do
    Polyn.Subscriber.start_link(__MODULE__, init_args,
      connection_name: :gnat,
      event: "user.created.v1")
  end

  def init(_arg) do
    {:ok, nil}
  end

  def handle_message(event, message, state) do
    # Do something cool with the event
    {:noreply, state}
  end
end

Link to this section Summary

Callbacks

Called when the subscribed event is published. Return the same values as you would for a Genserver.handle_info/2 callback

Functions

Returns a specification to start this module under a supervisor.

Options

  • :connection_name - Required, The pid or name of Gnat connection
  • :event - Required, The name of the event to subscribe to
  • :queue_group - a string that identifies which queue group you want to join

Any other passed options will be assumed to be GenServer options

Link to this section Types

@type start_options() ::
  GenServer.option() | {:connection_name, Gnat.t()} | {:event, binary()}

Link to this section Callbacks

Link to this callback

handle_message(event, msg, state)

View Source
@callback handle_message(event :: Polyn.Event.t(), msg :: Gnat.message(), state :: any()) ::
  {:noreply, new_state}
  | {:noreply, new_state, timeout() | :hibernate | {:continue, term()}}
  | {:stop, reason :: term(), new_state}
when new_state: term()

Called when the subscribed event is published. Return the same values as you would for a Genserver.handle_info/2 callback

Link to this section Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

Link to this function

start_link(module, init_args, options)

View Source
@spec start_link(module(), init_args :: any(), options :: [start_options()]) ::
  GenServer.on_start()

options

Options

  • :connection_name - Required, The pid or name of Gnat connection
  • :event - Required, The name of the event to subscribe to
  • :queue_group - a string that identifies which queue group you want to join

Any other passed options will be assumed to be GenServer options