Pixie.Monitor behaviour

Allows you to monitor various events within Pixie.

Internally Pixie.Monitor is implemented using GenEvent, so you're free to bypass using the Pixie.Monitor behaviour and use your own GenEvent if the need arises.

Usage example:

defmodule MyMonitor do
  use Pixie.Monitor

  def created_channel channel_name, at do
    Logger.info "Channel #{channel_name} created at #{format at}"
  end

  def destroyed_channel channel_name, at do
    Logger.info "Channel #{channel_name} destroyed at #{format at}"
  end

  defp format timestamp do
    timestamp
      |> Date.from(:timestamp)
      |> DateFormat.format!("{UNIX}")
  end
end
Source

Summary

add_handler(handler, args \\ [])

Allows you to add a Pixie.Monitor or any other GenEvent handler to the event stream. Expects the name of your handler module and any args which you wish to be provided to your module's init/1 callback

client_subscribed(client_id, channel_name)

Called by the backend when a client subscribes to a channel

client_unsubscribed(client_id, channel_name)

Called by the backend when a client unsubscribes from a channel

created_channel(channel_name)

Called by the backend when a new channel is created. New channels are created when the first client subscribes to them

created_client(client_id)

Called by the backend when a new client is created either by protocol handshake, or via Pixie.subscribe/2

delivered_message(publish)

Called by adapters when a message is finally delivered to a client

destroyed_channel(channel_name)

Called by the backend when a channel is destroyed. Channels are destroyed when the last client unsubscribes from them

destroyed_client(client_id)

Called by the backend when a client is destroyed, either by an expicit protocol disconnect or for a system generated reason, such as a timeout

received_message(publish)

Called whenever a new message is received for publication. This includes server-generated messages using Pixie.publish/2

start_link(handlers)

Functions

add_handler(handler, args \\ [])

Allows you to add a Pixie.Monitor or any other GenEvent handler to the event stream. Expects the name of your handler module and any args which you wish to be provided to your module's init/1 callback.

Source
client_subscribed(client_id, channel_name)

Called by the backend when a client subscribes to a channel.

Source
client_unsubscribed(client_id, channel_name)

Called by the backend when a client unsubscribes from a channel.

Source
created_channel(channel_name)

Called by the backend when a new channel is created. New channels are created when the first client subscribes to them.

Source
created_client(client_id)

Called by the backend when a new client is created either by protocol handshake, or via Pixie.subscribe/2

Source
delivered_message(publish)

Called by adapters when a message is finally delivered to a client.

Source
destroyed_channel(channel_name)

Called by the backend when a channel is destroyed. Channels are destroyed when the last client unsubscribes from them.

Source
destroyed_client(client_id)

Called by the backend when a client is destroyed, either by an expicit protocol disconnect or for a system generated reason, such as a timeout.

Source
received_message(publish)

Called whenever a new message is received for publication. This includes server-generated messages using Pixie.publish/2

Source
start_link(handlers)
Source

Callbacks

created_client/2

Specs:

  • created_client(client_id :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a new client is created during protocol handshake.

Source
destroyed_client/2

Specs:

  • destroyed_client(client_id :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a client is destroyed - either by an explicit disconnect request from the client, or by a system generated timeout.

Source
created_channel/2

Specs:

  • created_channel(channel_name :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a new channel is created - this happens when a client subscribes to it for the first time.

Source
destroyed_channel/2

Specs:

  • destroyed_channel(channel_name :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a channel is destroyed - this happens when the last client unsubscribes from it.

Source
client_subscribed/3

Specs:

  • client_subscribed(client_id :: binary, channel_name :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a client subscribes to a channel.

Source
client_unsubscribed/3

Specs:

  • client_unsubscribed(client_id :: binary, channel_name :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a client unsubscribes from a channel.

Source
received_message/3

Specs:

  • received_message(client_id :: binary, message_id :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a message is received with the ID of the message.

Some caveats:

  • This function is only called when a publish message is received, not when any protocol messages, such as connect or subscribe are received.
  • Message IDs are only unique per client, not globally.
  • If the message was generated on the server (ie via Pixie.publish/2) then the Client ID is likely to be nil.
Source
delivered_message/3

Specs:

  • delivered_message(client_id :: binary, message_id :: binary, at :: {megasecs :: integer, seconds :: integer, microsecs :: integer}) :: atom

Called when a message is delivered to a client.

Some caveats:

  • This function is only called when a publish message is delivered, not when any protocol messages, such as connect or subscribe are.
  • Message IDs are only unique per client, not globally.
  • The Client ID is that of the sender, not the receiver.
  • If the message was generated on the server (ie via Pixie.publish/2) then the Client ID is likely to be nil.
  • You will likely receive a lot of delivered calls for each received call as one message published to a channel may be relayed to thousands of receivers.
Source