omq_gleam

Gleam API for OMQ.

OMQ sockets are ZeroMQ-compatible message queues backed by the Rust omq-tokio runtime. Create a context with context or reuse the process-wide singleton with context_instance, then create sockets with socket.

Endpoints are UTF-8 bit arrays such as <<“tcp://127.0.0.1:5555”:utf8>>, <<“ipc:///tmp/omq.sock”:utf8>>, <<“inproc://queue”:utf8>>, <<“lz4+tcp://127.0.0.1:5555”:utf8>>, and <<“zstd+tcp://127.0.0.1:5555”:utf8>>.

Functions return Ok(value) or Error(#(class, reason)) unless they are pure constants or feature checks. send and recv move binary frames; string, JSON, term, multipart, pub/sub, RADIO/DISH, and socket option helpers wrap the Erlang base package.

Types

Opaque connection snapshot map from Erlang.

pub type ConnectionInfo

Native OMQ context resource.

pub type Context

Error tuple with class and reason.

pub type Error =
  #(String, String)

Socket monitor event stream resource.

pub type Monitor

Opaque monitor event map from Erlang.

pub type MonitorEvent

Native OMQ socket resource.

pub type Socket

Values

pub fn affinity() -> Int

Return AFFINITY constant.

pub fn backend_name() -> Result(BitArray, #(String, String))

Return native backend name.

pub fn backlog() -> Int

Return BACKLOG constant.

pub fn bind(
  socket: Socket,
  endpoint: BitArray,
) -> Result(BitArray, #(String, String))

Bind socket to endpoint and return bound endpoint.

pub fn bind_to_random_port(
  socket: Socket,
  addr: BitArray,
  min_port: Int,
  max_port: Int,
) -> Result(Int, #(String, String))

Bind socket to random port in inclusive range.

pub fn channel() -> Int

Return CHANNEL constant.

pub fn client() -> Int

Return CLIENT constant.

pub fn close(socket: Socket) -> Result(Nil, #(String, String))

Close socket with zero linger.

pub fn closed(socket: Socket) -> Bool

Return whether socket wrapper is closed.

pub fn configure_plain_server(
  socket: Socket,
  credentials: List(#(BitArray, BitArray)),
) -> Result(Nil, #(String, String))

Configure an exact, case-sensitive PLAIN server credential allowlist.

Call before bind, connect, send, or receive. Each username and password must contain at most 255 ASCII VCHAR bytes. An empty list rejects every client. PLAIN authenticates clients but does not encrypt traffic.

pub fn conflate() -> Int

Return CONFLATE constant.

pub fn connect(
  socket: Socket,
  endpoint: BitArray,
) -> Result(Nil, #(String, String))

Connect socket to endpoint.

pub fn connect_timeout() -> Int

Return CONNECT_TIMEOUT constant.

pub fn connection_info(
  socket: Socket,
  connection_id: Int,
) -> Result(ConnectionInfo, #(String, String))

Return one connection snapshot by ID.

pub fn connections(
  socket: Socket,
) -> Result(List(ConnectionInfo), #(String, String))

Return current connection snapshots for socket.

pub fn context() -> Result(Context, #(String, String))

Create a context with one IO thread.

pub fn context_closed(context: Context) -> Bool

Return whether context wrapper or native core is closed.

pub fn context_from_share_key(
  share_key: Int,
) -> Result(Context, #(String, String))

Import native context by share key.

pub fn context_instance() -> Result(Context, #(String, String))

Return process-wide singleton context.

pub fn context_instance_with_io_threads(
  io_threads: Int,
) -> Result(Context, #(String, String))

Return process-wide singleton context, creating it with IO thread count.

pub fn context_share_key(
  context: Context,
) -> Result(Int, #(String, String))

Return opaque native context share key.

pub fn curve() -> Int

Return CURVE constant.

pub fn curve_keypair() -> Result(
  #(BitArray, BitArray),
  #(String, String),
)

Generate CURVE public/secret keypair.

pub fn curve_public(
  secret: BitArray,
) -> Result(BitArray, #(String, String))

Derive CURVE public key from secret key.

pub fn curve_publickey() -> Int

Return CURVE_PUBLICKEY constant.

pub fn curve_secretkey() -> Int

Return CURVE_SECRETKEY constant.

pub fn curve_server() -> Int

Return CURVE_SERVER constant.

pub fn curve_serverkey() -> Int

Return CURVE_SERVERKEY constant.

pub fn dealer() -> Int

Return DEALER constant.

pub fn destroy(
  context: Context,
) -> Result(Nil, #(String, String))

Terminate a context. Alias for term.

pub fn device(
  device_type: Int,
  frontend: Socket,
  backend: Socket,
) -> Result(Nil, #(String, String))

Run libzmq-compatible device. Device type is accepted for parity.

pub fn disconnect(
  socket: Socket,
  endpoint: BitArray,
) -> Result(Nil, #(String, String))

Disconnect socket from endpoint.

pub fn dish() -> Int

Return DISH constant.

pub fn dontwait() -> Int

Return DONTWAIT constant.

pub fn events() -> Int

Return EVENTS constant.

pub fn fd() -> Int

Return FD constant.

pub fn forwarder() -> Int

Return FORWARDER constant.

pub fn from_share_key(
  share_key: Int,
) -> Result(Context, #(String, String))

Import native context by share key.

pub fn gather() -> Int

Return GATHER constant.

pub fn get_hwm(socket: Socket) -> Result(Int, #(String, String))

Return SNDHWM as compatibility HWM value.

pub fn getsockopt_binary(
  socket: Socket,
  option: Int,
) -> Result(BitArray, #(String, String))

Get binary socket option.

pub fn getsockopt_int(
  socket: Socket,
  option: Int,
) -> Result(Int, #(String, String))

Get integer socket option.

pub fn getsockopt_string(
  socket: Socket,
  option: Int,
) -> Result(String, #(String, String))

Get binary socket option as UTF-8 string.

pub fn handshake_ivl() -> Int

Return HANDSHAKE_IVL constant.

pub fn has(capability: BitArray) -> Bool

Return whether native feature or transport is available.

pub fn heartbeat_ivl() -> Int

Return HEARTBEAT_IVL constant.

pub fn heartbeat_timeout() -> Int

Return HEARTBEAT_TIMEOUT constant.

pub fn heartbeat_ttl() -> Int

Return HEARTBEAT_TTL constant.

pub fn hwm() -> Int

Return HWM constant.

pub fn identity() -> Int

Return IDENTITY constant.

pub fn immediate() -> Int

Return IMMEDIATE constant.

pub fn instance() -> Result(Context, #(String, String))

Return process-wide singleton context.

pub fn instance_with_io_threads(
  io_threads: Int,
) -> Result(Context, #(String, String))

Return process-wide singleton context, creating it with IO thread count.

pub fn ipv4only() -> Int

Return IPV4ONLY constant.

pub fn ipv6() -> Int

Return IPV6 constant.

pub fn join(
  socket: Socket,
  group: BitArray,
) -> Result(Nil, #(String, String))

Join RADIO/DISH group.

pub fn last_endpoint() -> Int

Return LAST_ENDPOINT constant.

pub fn leave(
  socket: Socket,
  group: BitArray,
) -> Result(Nil, #(String, String))

Leave RADIO/DISH group.

pub fn linger() -> Int

Return LINGER constant.

pub fn maxmsgsize() -> Int

Return MAXMSGSIZE constant.

pub fn mechanism() -> Int

Return MECHANISM constant.

pub fn monitor(
  socket: Socket,
) -> Result(Monitor, #(String, String))

Create monitor stream for socket lifecycle events.

pub fn monitor_recv(
  monitor: Monitor,
  timeout_ms: Int,
) -> Result(MonitorEvent, #(String, String))

Receive next monitor event with timeout in milliseconds.

pub fn monitor_try_recv(
  monitor: Monitor,
) -> Result(MonitorEvent, #(String, String))

Try to receive one monitor event without blocking.

pub fn multicast_hops() -> Int

Return MULTICAST_HOPS constant.

pub fn noblock() -> Int

Return NOBLOCK constant.

pub fn null() -> Int

Return NULL constant.

pub fn omq_compression_auto_train() -> Int

Return OMQ_COMPRESSION_AUTO_TRAIN constant.

pub fn omq_compression_dict() -> Int

Return OMQ_COMPRESSION_DICT constant.

pub fn omq_compression_level() -> Int

Return OMQ_COMPRESSION_LEVEL constant.

pub fn omq_on_mute() -> Int

Return OMQ_ON_MUTE constant.

pub fn omq_on_mute_block() -> Int

Return OMQ_ON_MUTE block mode value.

pub fn omq_on_mute_drop_newest() -> Int

Return OMQ_ON_MUTE drop-newest mode value.

pub fn omq_on_mute_drop_oldest() -> Int

Return OMQ_ON_MUTE drop-oldest mode value.

pub fn omq_version() -> Result(BitArray, #(String, String))

Return native binding version. Alias for version.

pub fn omq_version_info() -> Result(
  #(Int, Int, Int),
  #(String, String),
)

Return native binding version as #(major, minor, patch).

pub fn omq_workload_profile() -> Int

Return OMQ_WORKLOAD_PROFILE constant.

pub fn pair() -> Int

Return PAIR constant.

pub fn peer() -> Int

Return PEER constant.

pub fn plain() -> Int

Return PLAIN constant.

pub fn plain_password() -> Int

Return PLAIN_PASSWORD constant.

pub fn plain_server() -> Int

Return PLAIN_SERVER constant.

pub fn plain_username() -> Int

Return PLAIN_USERNAME constant.

pub fn pollerr() -> Int

Return POLLERR constant.

pub fn pollin() -> Int

Return POLLIN constant.

pub fn pollout() -> Int

Return POLLOUT constant.

pub fn pollpri() -> Int

Return POLLPRI constant.

pub fn probe_router() -> Int

Return PROBE_ROUTER constant.

pub fn proxy(
  frontend: Socket,
  backend: Socket,
) -> Result(Nil, #(String, String))

Run bidirectional proxy between two sockets.

pub fn proxy_steerable(
  frontend: Socket,
  backend: Socket,
  capture: Socket,
  control: Socket,
) -> Result(Nil, #(String, String))

Run steerable proxy with PAUSE, RESUME, and TERMINATE control.

pub fn proxy_with_capture(
  frontend: Socket,
  backend: Socket,
  capture: Socket,
) -> Result(Nil, #(String, String))

Run proxy and mirror traffic to capture socket.

pub fn publisher() -> Int

Return PUB socket type constant.

pub fn pull() -> Int

Return PULL constant.

pub fn push() -> Int

Return PUSH constant.

pub fn queue() -> Int

Return QUEUE constant.

pub fn radio() -> Int

Return RADIO constant.

pub fn rate() -> Int

Return RATE constant.

pub fn rcvbuf() -> Int

Return RCVBUF constant.

pub fn rcvhwm() -> Int

Return RCVHWM constant.

pub fn rcvmore() -> Int

Return RCVMORE constant.

pub fn rcvtimeo() -> Int

Return RCVTIMEO constant.

pub fn reconnect_ivl() -> Int

Return RECONNECT_IVL constant.

pub fn reconnect_ivl_max() -> Int

Return RECONNECT_IVL_MAX constant.

pub fn reconnect_stop() -> Int

Return RECONNECT_STOP constant.

pub fn recovery_ivl() -> Int

Return RECOVERY_IVL constant.

pub fn recv(
  socket: Socket,
) -> Result(BitArray, #(String, String))

Receive one binary message.

pub fn recv_frame(
  socket: Socket,
) -> Result(BitArray, #(String, String))

Receive next frame from multipart message.

pub fn recv_json(
  socket: Socket,
) -> Result(dynamic.Dynamic, #(String, String))

Receive one JSON value decoded by OTP json.

pub fn recv_multipart(
  socket: Socket,
) -> Result(List(BitArray), #(String, String))

Receive one multipart message.

pub fn recv_string(
  socket: Socket,
) -> Result(String, #(String, String))

Receive one UTF-8 string message.

pub fn recv_string_timeout(
  socket: Socket,
  timeout_ms: Int,
) -> Result(String, #(String, String))

Receive one string with timeout in milliseconds.

pub fn recv_term(
  socket: Socket,
) -> Result(dynamic.Dynamic, #(String, String))

Receive one Erlang term encoded by send_term.

pub fn rep() -> Int

Return REP constant.

pub fn req() -> Int

Return REQ constant.

pub fn req_correlate() -> Int

Return REQ_CORRELATE constant.

pub fn req_relaxed() -> Int

Return REQ_RELAXED constant.

pub fn router() -> Int

Return ROUTER constant.

pub fn router_handover() -> Int

Return ROUTER_HANDOVER constant.

pub fn router_mandatory() -> Int

Return ROUTER_MANDATORY constant.

pub fn routing_id() -> Int

Return ROUTING_ID constant.

pub fn scatter() -> Int

Return SCATTER constant.

pub fn send(
  socket: Socket,
  data: BitArray,
) -> Result(Nil, #(String, String))

Send one binary message.

pub fn send_group(
  socket: Socket,
  group: BitArray,
  body: BitArray,
) -> Result(Nil, #(String, String))

Send RADIO message to group.

pub fn send_json(
  socket: Socket,
  value: dynamic.Dynamic,
) -> Result(Nil, #(String, String))

Send one JSON value encoded by OTP json.

pub fn send_multipart(
  socket: Socket,
  parts: List(BitArray),
) -> Result(Nil, #(String, String))

Send one multipart message.

pub fn send_string(
  socket: Socket,
  text: String,
) -> Result(Nil, #(String, String))

Send one UTF-8 string message.

pub fn send_term(
  socket: Socket,
  term: dynamic.Dynamic,
) -> Result(Nil, #(String, String))

Send one Erlang term using external term format.

pub fn server() -> Int

Return SERVER constant.

pub fn set_hwm(
  socket: Socket,
  value: Int,
) -> Result(Nil, #(String, String))

Set both SNDHWM and RCVHWM.

pub fn setsockopt_binary(
  socket: Socket,
  option: Int,
  value: BitArray,
) -> Result(Nil, #(String, String))

Set binary socket option.

pub fn setsockopt_int(
  socket: Socket,
  option: Int,
  value: Int,
) -> Result(Nil, #(String, String))

Set integer socket option.

pub fn setsockopt_string(
  socket: Socket,
  option: Int,
  value: String,
) -> Result(Nil, #(String, String))

Set binary socket option from UTF-8 string.

pub fn share_key(
  context: Context,
) -> Result(Int, #(String, String))

Return opaque native context share key.

pub fn sndbuf() -> Int

Return SNDBUF constant.

pub fn sndhwm() -> Int

Return SNDHWM constant.

pub fn sndmore() -> Int

Return SNDMORE constant.

pub fn sndtimeo() -> Int

Return SNDTIMEO constant.

pub fn socket(
  context: Context,
  socket_type: Int,
) -> Result(Socket, #(String, String))

Create socket from context and socket type constant.

pub fn socket_id(
  socket: Socket,
) -> Result(Int, #(String, String))

Return wrapper socket ID.

pub fn socket_type(
  socket: Socket,
) -> Result(String, #(String, String))

Return socket type atom name as string.

pub fn stream() -> Int

Return STREAM constant.

pub fn streamer() -> Int

Return STREAMER constant.

pub fn strerror(errno: Int) -> BitArray

Return POSIX strerror text for common libzmq errno values.

pub fn subscribe(
  socket: Socket,
  prefix: BitArray,
) -> Result(Nil, #(String, String))

Subscribe SUB or XSUB socket to prefix.

pub fn subscribe_opt() -> Int

Return SUBSCRIBE option ID.

pub fn subscriber() -> Int

Return SUB socket type constant.

pub fn tcp_accept_filter() -> Int

Return TCP_ACCEPT_FILTER constant.

pub fn tcp_keepalive() -> Int

Return TCP_KEEPALIVE constant.

pub fn tcp_keepalive_cnt() -> Int

Return TCP_KEEPALIVE_CNT constant.

pub fn tcp_keepalive_idle() -> Int

Return TCP_KEEPALIVE_IDLE constant.

pub fn tcp_keepalive_intvl() -> Int

Return TCP_KEEPALIVE_INTVL constant.

pub fn tcp_maxrt() -> Int

Return TCP_MAXRT constant.

pub fn term(context: Context) -> Result(Nil, #(String, String))

Terminate a context.

pub fn try_recv(
  socket: Socket,
) -> Result(BitArray, #(String, String))

Try to receive one binary message without blocking.

pub fn try_recv_json(
  socket: Socket,
) -> Result(dynamic.Dynamic, #(String, String))

Try to receive one JSON value without blocking.

pub fn try_recv_multipart(
  socket: Socket,
) -> Result(List(BitArray), #(String, String))

Try to receive one multipart message without blocking.

pub fn try_recv_string(
  socket: Socket,
) -> Result(String, #(String, String))

Try to receive one UTF-8 string without blocking.

pub fn try_recv_term(
  socket: Socket,
) -> Result(dynamic.Dynamic, #(String, String))

Try to receive one Erlang term without blocking.

pub fn type_option() -> Int

Return TYPE option ID.

pub fn unbind(
  socket: Socket,
  endpoint: BitArray,
) -> Result(Nil, #(String, String))

Unbind socket from endpoint.

pub fn unsubscribe(
  socket: Socket,
  prefix: BitArray,
) -> Result(Nil, #(String, String))

Remove SUB or XSUB prefix subscription.

pub fn unsubscribe_opt() -> Int

Return UNSUBSCRIBE option ID.

pub fn version() -> Result(BitArray, #(String, String))

Return native binding version.

pub fn wait_connected(
  socket: Socket,
  min_peers: Int,
  timeout_ms: Int,
) -> Result(Int, #(String, String))

Wait until minimum peer count is connected.

pub fn wait_subscribed(
  socket: Socket,
  min_subscriptions: Int,
  timeout_ms: Int,
) -> Result(Int, #(String, String))

Wait until minimum subscription generation is visible.

pub fn xpub() -> Int

Return XPUB constant.

pub fn xpub_verbose() -> Int

Return XPUB_VERBOSE constant.

pub fn xsub() -> Int

Return XSUB constant.

pub fn zap_domain() -> Int

Return ZAP_DOMAIN constant.

pub fn zmq_version() -> BitArray

Return libzmq compatibility version string.

pub fn zmq_version_info() -> #(Int, Int, Int)

Return libzmq compatibility version tuple.

Search Document