glixir/syn_pubsub

Syn PubSub bridge for Gleam actors.

Similar to glixir/pubsub but uses :syn instead of Phoenix.PubSub. Messages are passed as strings (typically JSON) for type-safe interop.

Types

Errors from syn pubsub operations

pub type SynPubSubError {
  SubscribeError(String)
  PublishError(String)
}

Constructors

  • SubscribeError(String)
  • PublishError(String)
pub type SynPubSubPublishResult {
  SynPubsubPublishOk(count: Int)
  SynPubsubPublishError(reason: dynamic.Dynamic)
}

Constructors

  • SynPubsubPublishOk(count: Int)
  • SynPubsubPublishError(reason: dynamic.Dynamic)
pub type SynPubSubSubscribeResult {
  SynPubsubSubscribeOk
  SynPubsubSubscribeError(reason: dynamic.Dynamic)
}

Constructors

Values

pub fn publish(
  scope: String,
  group: String,
  message: String,
) -> Result(Int, SynPubSubError)

Publish a message to all subscribers of a syn pubsub group Returns the number of processes the message was delivered to

Example

syn_pubsub.publish("job_completions", "all", job_id)
|> result.map(fn(count) {
  logging.log(Info, "Sent to " <> int.to_string(count) <> " subscribers")
})
pub fn subscribe(
  scope: String,
  group: String,
  gleam_module: String,
  gleam_function: String,
) -> Result(Nil, SynPubSubError)

Subscribe to a syn pubsub group with message handling The gleam_function must accept a single String parameter (typically JSON) and return Nil

Example

syn_pubsub.subscribe(
  "job_completions",
  "all",
  "actors@url_queue_actor",
  "handle_job_cancellation"
)
pub fn subscribe_with_registry_key(
  scope: String,
  group: String,
  gleam_module: String,
  gleam_function: String,
  registry_key: String,
) -> Result(Nil, SynPubSubError)

Subscribe to a syn pubsub group with registry key for direct actor targeting The gleam_function must accept two String parameters (registry_key, message) and return Nil

Example

syn_pubsub.subscribe_with_registry_key(
  "job_completions",
  "all",
  "actors@url_queue_actor",
  "handle_job_cancellation",
  "https://api.example.com/endpoint"
)
Search Document