zmq

ZeroMQ bindings for Kit via czmq - high-performance messaging for distributed applications

Files

FileDescription
kit.tomlPackage manifest with metadata and dependencies
src/main.kitMain module - exports all public functions and types
tests/zmq.test.kitTests for socket type constants
examples/pub-sub-publisher.kitPUB socket broadcasting messages
examples/pub-sub-subscriber.kitSUB socket receiving filtered messages
examples/push-pull-ventilator.kitPUSH socket distributing tasks
examples/push-pull-worker.kitPULL socket receiving and processing tasks
examples/req-rep-client.kitREQ socket sending requests
examples/req-rep-server.kitREP socket handling request-reply
examples/simple-test.kitSocket creation and type inspection
LICENSEMIT license file

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-zmq.git

Usage

import Kit.Zmq

License

MIT License - see LICENSE for details.

Exported Functions & Types

ZMQError

ZeroMQ error type for typed error handling.

Variants

ZMQSocketError {message}
ZMQBindError {message}
ZMQConnectError {message}
ZMQSendError {message}
ZMQRecvError {message}

zmq-pair

PAIR socket type constant.

zmq-pub

PUB socket type constant.

zmq-sub

SUB socket type constant.

zmq-req

REQ socket type constant.

zmq-rep

REP socket type constant.

zmq-dealer

DEALER socket type constant.

zmq-router

ROUTER socket type constant.

zmq-pull

PULL socket type constant.

zmq-push

PUSH socket type constant.

zmq-xpub

XPUB socket type constant.

zmq-xsub

XSUB socket type constant.

zmq-stream

STREAM socket type constant.

req

Creates a REQ (request) socket and connects to the endpoint.

REQ sockets are used in request-reply patterns. They send a request and then wait for a reply. Must alternate between send and receive.

Parameters:

Returns:

String -> Result Ptr ZMQError

match ZMQ.req "tcp://localhost:5555"
| Ok socket ->
  ZMQ.send socket "Hello"
  reply = ZMQ.recv socket
  ZMQ.close socket
| Err e -> print "Failed: ${show e}"

rep

Creates a REP (reply) socket and binds to the endpoint.

REP sockets are used in request-reply patterns. They receive a request and then send a reply. Must alternate between receive and send.

Parameters:

Returns:

String -> Result Ptr ZMQError

pub

Creates a PUB (publish) socket and binds to the endpoint.

PUB sockets broadcast messages to all connected SUB subscribers. Messages are dropped if no subscribers are connected.

Parameters:

Returns:

String -> Result Ptr ZMQError

sub

Creates a SUB (subscribe) socket and connects to the endpoint.

SUB sockets receive messages from PUB publishers. By default, subscribes to all messages (empty string filter).

Parameters:

Returns:

String -> String -> Result Ptr ZMQError

push

Creates a PUSH socket and connects to the endpoint.

PUSH sockets send messages in a pipeline pattern. Messages are round-robin distributed to connected PULL sockets.

Parameters:

Returns:

String -> Result Ptr ZMQError

pull

Creates a PULL socket and binds to the endpoint.

PULL sockets receive messages in a pipeline pattern. Messages are fair-queued from connected PUSH sockets.

Parameters:

Returns:

String -> Result Ptr ZMQError

dealer

Creates a DEALER socket and connects to the endpoint.

DEALER sockets are advanced request-reply sockets that can send multiple requests without waiting for replies.

Parameters:

Returns:

String -> Result Ptr ZMQError

router

Creates a ROUTER socket and binds to the endpoint.

ROUTER sockets are advanced reply sockets that can handle multiple clients asynchronously.

Parameters:

Returns:

String -> Result Ptr ZMQError

pair

Creates a PAIR socket and connects/binds to the endpoint.

PAIR sockets are for exclusive one-to-one communication between two peers.

Parameters:

Returns:

String -> Result Ptr ZMQError

send

Sends a string message on a socket.

Parameters:

Returns:

Ptr -> String -> Result Unit ZMQError

ZMQ.send socket "Hello, World!"

send-more

Sends a string message with MORE flag (for multipart messages).

Parameters:

Returns:

Ptr -> String -> Result Unit ZMQError

recv

Receives a string message from a socket (blocking).

Parameters:

Returns:

Ptr -> String

message = ZMQ.recv socket
print "Received: ${message}"

recv-nowait

Receives a string message from a socket (non-blocking).

Parameters:

Returns:

Ptr -> String

close

Closes and destroys a socket.

Parameters:

Ptr -> Unit

ZMQ.close socket

bind

Binds a socket to an additional endpoint.

Parameters:

Returns:

Ptr -> String -> Result Int ZMQError

connect

Connects a socket to an additional endpoint.

Parameters:

Returns:

Ptr -> String -> Result Unit ZMQError

subscribe

Subscribes to messages matching a prefix (SUB sockets only).

Parameters:

    Ptr -> String -> Unit

unsubscribe

Unsubscribes from messages matching a prefix (SUB sockets only).

Parameters:

    Ptr -> String -> Unit

set-recv-timeout

Sets the receive timeout in milliseconds.

Parameters:

    Ptr -> Int -> Unit

set-send-timeout

Sets the send timeout in milliseconds.

Parameters:

    Ptr -> Int -> Unit

set-linger

Sets the linger period for socket shutdown.

Parameters:

    Ptr -> Int -> Unit

set-identity

Sets the socket identity (for DEALER/ROUTER sockets).

Parameters:

    Ptr -> String -> Unit

type-str

Gets the socket type as a string.

Parameters:

Returns:

Ptr -> String

get-endpoint

Gets the last bound endpoint.

Parameters:

Returns:

Ptr -> String