goose

Types

pub type AccountData {
  AccountData(active: Bool, did: String, seq: Int, time: String)
}

Constructors

  • AccountData(active: Bool, did: String, seq: Int, time: String)
pub type CommitData {
  CommitData(
    rev: String,
    operation: String,
    collection: String,
    rkey: String,
    record: option.Option(dynamic.Dynamic),
    cid: option.Option(String),
  )
}

Constructors

pub type IdentityData {
  IdentityData(
    did: String,
    handle: String,
    seq: Int,
    time: String,
  )
}

Constructors

  • IdentityData(did: String, handle: String, seq: Int, time: String)

Configuration for Jetstream consumer

pub type JetstreamConfig {
  JetstreamConfig(
    endpoint: String,
    wanted_collections: List(String),
    wanted_dids: List(String),
    cursor: option.Option(Int),
    max_message_size_bytes: option.Option(Int),
    compress: Bool,
    require_hello: Bool,
    max_backoff_seconds: Int,
    log_connection_events: Bool,
    log_retry_attempts: Bool,
  )
}

Constructors

  • JetstreamConfig(
      endpoint: String,
      wanted_collections: List(String),
      wanted_dids: List(String),
      cursor: option.Option(Int),
      max_message_size_bytes: option.Option(Int),
      compress: Bool,
      require_hello: Bool,
      max_backoff_seconds: Int,
      log_connection_events: Bool,
      log_retry_attempts: Bool,
    )

    Arguments

    max_backoff_seconds

    Maximum backoff time in seconds for retry logic (default: 60)

    log_connection_events

    Whether to log connection events (connected, disconnected) (default: True)

    log_retry_attempts

    Whether to log retry attempts and errors (default: True)

Jetstream event types

pub type JetstreamEvent {
  CommitEvent(did: String, time_us: Int, commit: CommitData)
  IdentityEvent(
    did: String,
    time_us: Int,
    identity: IdentityData,
  )
  AccountEvent(did: String, time_us: Int, account: AccountData)
  UnknownEvent(raw: String)
}

Constructors

  • CommitEvent(did: String, time_us: Int, commit: CommitData)
  • IdentityEvent(did: String, time_us: Int, identity: IdentityData)
  • AccountEvent(did: String, time_us: Int, account: AccountData)
  • UnknownEvent(raw: String)

Values

pub fn build_url(config: JetstreamConfig) -> String

Build the WebSocket URL with query parameters

pub fn connect(
  url: String,
  handler_pid: process.Pid,
  compress: Bool,
) -> Result(process.Pid, dynamic.Dynamic)

Connect to Jetstream WebSocket using Erlang gun library

pub fn default_config() -> JetstreamConfig

Create a default configuration for US East endpoint Includes automatic retry with exponential backoff (1s, 2s, 4s, 8s, 16s, 32s, capped at 60s)

pub fn parse_event(json_string: String) -> JetstreamEvent

Parse a JSON event string into a JetstreamEvent

pub fn start_consumer(
  config: JetstreamConfig,
  on_event: fn(String) -> Nil,
) -> Nil

Start consuming the Jetstream feed with automatic retry logic

Handles connection failures gracefully with exponential backoff and automatic reconnection. The retry behavior is configured through the JetstreamConfig fields:

  • max_backoff_seconds: Maximum wait time between retries
  • log_connection_events: Log connects/disconnects
  • log_retry_attempts: Log retry attempts and errors

Example:

let config = goose.default_config()

goose.start_consumer(config, fn(event_json) {
  // Handle event
  io.println(event_json)
})
Search Document