gamqp/amqp091/connection

Connections to an AMQP 0-9-1 broker.

A connection is a process linked to the one that opened it: if your process exits, the connection goes with it. Losing the connection does not crash your process; calls start returning errors and consumers receive Cancelled. Monitor pid(connection) to reconnect.

Types

pub type AuthMechanism {
  Plain
  AmqPlain
  External
}

Constructors

  • Plain

    Username and password, the broker default.

  • AmqPlain
  • External

    Authenticate with the TLS client certificate.

pub type Config {
  Config(
    host: String,
    port: Int,
    username: String,
    password: String,
    virtual_host: String,
    auth_mechanism: AuthMechanism,
    tls: option.Option(tls.TlsConfig),
    heartbeat: Int,
    frame_max: Int,
    channel_max: Int,
    connection_timeout: Int,
    call_timeout: Int,
    name: option.Option(String),
  )
}

Constructors

  • Config(
      host: String,
      port: Int,
      username: String,
      password: String,
      virtual_host: String,
      auth_mechanism: AuthMechanism,
      tls: option.Option(tls.TlsConfig),
      heartbeat: Int,
      frame_max: Int,
      channel_max: Int,
      connection_timeout: Int,
      call_timeout: Int,
      name: option.Option(String),
    )

    Arguments

    heartbeat

    Seconds. 0 lets the broker decide.

    frame_max

    Largest frame in bytes. 0 lets the broker decide.

    channel_max

    Most channels open at once. 0 lets the broker decide.

    connection_timeout

    Milliseconds allowed for the TCP/TLS connect and the AMQP handshake.

    call_timeout

    Milliseconds to wait for the broker to answer a method.

    name

    Shown in the RabbitMQ management UI.

Values

pub fn channel_max(connection: client.Connection) -> Int
pub fn close(
  connection: client.Connection,
) -> Result(Nil, core.AmqpError)

Closes every channel and the connection. Closing twice is fine.

pub fn default_config() -> Config

guest:guest@localhost:5672, vhost /, 60 second heartbeat.

pub fn frame_max(connection: client.Connection) -> Int

Values agreed during the handshake.

pub fn from_uri(value: String) -> Result(Config, String)

Parses an amqp:// or amqps:// URI as RabbitMQ documents them, e.g. amqps://user:secret@broker.example.com/production?heartbeat=30.

Supported query parameters: heartbeat, frame_max, channel_max, connection_timeout (ms), auth_mechanism and connection_name.

pub fn heartbeat(connection: client.Connection) -> Int
pub fn is_open(connection: client.Connection) -> Bool
pub fn on_blocked(
  connection: client.Connection,
  subject: process.Subject(event.Blocked),
) -> Nil

Sends Blocked/Unblocked to subject whenever the broker stops or resumes accepting publishes on this connection.

pub fn open(
  config: Config,
) -> Result(client.Connection, core.AmqpError)

Connects and runs the AMQP handshake.

pub fn pid(connection: client.Connection) -> process.Pid

The connection process, for monitoring.

pub fn server_properties(
  connection: client.Connection,
) -> List(#(String, table.FieldValue))

What the broker said about itself: product, version, capabilities…

pub fn update_secret(
  connection: client.Connection,
  secret: String,
  reason: String,
) -> Result(Nil, core.AmqpError)

Replaces the credentials of a live connection, typically an expiring OAuth 2 token on RabbitMQ.

✨ Search Document