Jido.Messaging.OutboundGateway (Jido Messaging v1.0.0)

Copy Markdown View Source

Partitioned outbound gateway for send/edit delivery operations.

The gateway enforces:

  • Stable partition routing by bridge_id:external_room_id
  • Bounded per-partition queues with pressure transition signals
  • Normalized outbound error categories for retry and terminal handling

Summary

Functions

Normalize raw provider/channel failures into gateway categories.

Returns gateway config for an instance module.

Returns configured partition count for the gateway.

Resolve a stable partition for a routing key tuple.

Returns a stable routing key used by partition hashing.

Send media through the outbound gateway.

Send a message through the outbound gateway.

Types

error_category()

@type error_category() :: :retryable | :terminal | :fatal

error_response()

@type error_response() :: %{
  type: :outbound_error,
  category: error_category(),
  disposition: :retry | :terminal,
  operation: operation(),
  reason: term(),
  attempt: pos_integer(),
  max_attempts: pos_integer(),
  partition: non_neg_integer(),
  routing_key: String.t(),
  retryable: boolean()
}

operation()

@type operation() :: :send | :edit | :send_media | :edit_media

priority()

@type priority() :: :critical | :high | :normal | :low

request()

@type request() :: %{
  :operation => operation(),
  :channel => module(),
  :bridge_id => String.t(),
  :external_room_id => term(),
  :payload => String.t() | map(),
  :opts => keyword(),
  :routing_key => String.t(),
  :session_key => Jido.Messaging.SessionManager.session_key(),
  optional(:external_message_id) => term(),
  optional(:route_resolution) => Jido.Messaging.SessionManager.resolution(),
  optional(:idempotency_key) => String.t() | nil,
  optional(:max_attempts) => pos_integer() | nil,
  optional(:base_backoff_ms) => pos_integer() | nil,
  optional(:max_backoff_ms) => pos_integer() | nil,
  optional(:priority) => priority()
}

success_response()

@type success_response() :: %{
  :operation => operation(),
  :message_id => term(),
  :result => map(),
  :partition => non_neg_integer(),
  :attempts => pos_integer(),
  :routing_key => String.t(),
  :pressure_level => :normal | :warn | :degraded | :shed,
  :idempotent => boolean(),
  optional(:route_resolution) => Jido.Messaging.SessionManager.resolution(),
  optional(:security) => map(),
  optional(:media) => map()
}

Functions

classify_error(reason)

@spec classify_error(term()) :: error_category()

Normalize raw provider/channel failures into gateway categories.

config(instance_module)

@spec config(module()) :: keyword()

Returns gateway config for an instance module.

edit_media(instance_module, context, external_message_id, media_payload, opts \\ [])

@spec edit_media(module(), map(), term(), map(), keyword()) ::
  {:ok, success_response()} | {:error, error_response()}

Edit media through the outbound gateway.

edit_message(instance_module, context, external_message_id, text, opts \\ [])

@spec edit_message(module(), map(), term(), String.t(), keyword()) ::
  {:ok, success_response()} | {:error, error_response()}

Edit a message through the outbound gateway.

partition_count(instance_module)

@spec partition_count(module()) :: pos_integer()

Returns configured partition count for the gateway.

route_partition(instance_module, bridge_id, external_room_id)

@spec route_partition(module(), String.t(), term()) :: non_neg_integer()

Resolve a stable partition for a routing key tuple.

routing_key(bridge_id, external_room_id)

@spec routing_key(String.t(), term()) :: String.t()

Returns a stable routing key used by partition hashing.

send_media(instance_module, context, media_payload, opts \\ [])

@spec send_media(module(), map(), map(), keyword()) ::
  {:ok, success_response()} | {:error, error_response()}

Send media through the outbound gateway.

send_message(instance_module, context, text, opts \\ [])

@spec send_message(module(), map(), String.t(), keyword()) ::
  {:ok, success_response()} | {:error, error_response()}

Send a message through the outbound gateway.