glats/handler

This module provides a subscription handler that can be used to subscribe to NATS subjects and receive them in your own handler.

Types

Callback handler that should be provided to handle_subscription to process the received messages from a subscription.

pub type MessageHandler =
  fn(Message, Subject(Command)) -> Result(Nil, String)

Request includes headers and body from a request message.

pub type Request {
  Request(headers: Map(String, String), body: String)
}

Constructors

  • Request(headers: Map(String, String), body: String)

Callback handler that should be provided to handle_request to process the the received request and return a response.

pub type RequestHandler =
  fn(Request, Subject(Command)) -> Result(Response, String)

Response includes headers and body for a response to a request.

pub type Response {
  Response(headers: Map(String, String), body: String)
}

Constructors

  • Response(headers: Map(String, String), body: String)

Functions

pub fn handle_request(conn: Subject(Command), subject: String, handler: fn(
    Request,
    Subject(Command),
  ) -> Result(Response, String)) -> Result(
  Subject(Message),
  StartError,
)

Starts an actor that will handle received requests on a NATS subject and handle responding to them with what’s returned from the provided handler.

pub fn handle_subscription(conn: Subject(Command), subject: String, handler: fn(
    Message,
    Subject(Command),
  ) -> Result(Nil, String)) -> Result(
  Subject(Message),
  StartError,
)

Starts an actor that will handle receiving messages from a NATS subject and call your handler.

Search Document