Reference
ZMQ.lib_version — Function
lib_version()Get the libzmq version number.
ZMQ.TimeoutError — Type
Exception thrown by the recv*() methods if rcvtimeo is set and a receive times out, or a Poller. The timeout itself can be obtained from the timeout_secs property of the exception.
Sockets
The ZMQ Socket type:
ZMQ.Socket — Type
A ZMQ socket.
ZMQ.Socket — Method
Socket(ctx::Context, typ::Integer)Create a socket in a given context.
ZMQ.Socket — Method
Socket(typ::Integer)Create a socket of a certain type.
ZMQ.Socket — Method
Socket(f::Function, args...)Do-block constructor.
Base.isopen — Method
Base.isopen(socket::Socket)Base.close — Method
Base.close(socket::Socket)Socket implements the Sockets interface:
Sockets.connect — Function
Sockets.connect(socket::Socket, endpoint::AbstractString)Connect the socket to an endpoint.
Sockets.recv — Function
recv(socket::Socket)Return a Message object representing a message received from a ZMQ Socket (without making a copy of the message data).
If rcvtimeo is set then a TimeoutError will be thrown upon timeout. Note that because of the integration with Julia's event loop there is some overhead to using timeouts, on the order of ~10μs. All other recv*() methods also respect rcvtimeo.
recv(socket::Socket, ::Type{T})Receive a message of type T (typically a String, Vector{UInt8}, or isbits type) from a ZMQ Socket. (Makes a copy of the message data; you can alternatively use recv(socket) to work with zero-copy bytearray-like representation for large messages.)
ZMQ.recv_multipart — Function
recv_multipart(socket::Socket, ::Type{T}) -> Vector{T}Receive a multipart message of a specific type T. This behaves in the same way as recv(::Socket, ::Type).
recv_multipart(socket::Socket) -> Vector{Message}Receive a multipart message as a sequence of zero-copy Message's. See recv(::Socket).
Sockets.send — Function
send(socket::Socket, data; more=false)Send data over socket. A more=true keyword argument can be passed to indicate that data is a portion of a larger multipart message. data can be any isbits type, a Vector of isbits elements, a String, or a Message object to perform zero-copy sends of large arrays.
send(socket::Socket, zmsg::Message; more::Bool=false)Zero-copy version of Sockets.send(socket, data) using a user-allocated Message.
ZMQ.send_multipart — Function
send_multipart(socket::Socket, parts)Send a multipart message composed of the elements in parts. parts may be any object that supports getindex(), eachindex(), and lastindex().
ZMQ socket types (note: some of these are aliases; e.g. XREQ = DEALER):
ZMQ.DEALER — Constant
DEALER socket.
ZMQ.ROUTER — Constant
ROUTER socket.
ZMQ.XREQ — Constant
XREQ socket.
This is a deprecated alias for ZMQ.DEALER.
ZMQ.XREP — Constant
XREP socket.
This is a deprecated alias for ZMQ.ROUTER.
ZMQ.UPSTREAM — Constant
ZMQ.DOWNSTREAM — Constant
DOWNSTREAM socket.
This is a deprecated alias for ZMQ.PUSH.
Messages
ZMQ.Message — Type
mutable struct Message <: AbstractArray{UInt8, 1}High-level Message object for sending/receiving ZMQ messages in shared buffers. As an AbstractArray, it supports common (non-resizeable) array behaviour.
Examples
julia> using ZMQ
julia> m = Message("foo");
julia> Char(m[1]) # Array indexing
'f': ASCII/Unicode U+0066 (category Ll: Letter, lowercase)
julia> m[end] = Int('g'); # Array assignment
julia> unsafe_string(m) # Conversion to string (only do this if you know the message is a string)
"fog"
julia> IOBuffer(m) # Create a zero-copy IOBuffer
IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=3, maxsize=Inf, ptr=1, mark=-1)ZMQ.Message — Method
Message()Create an empty message (for receive).
ZMQ.Message — Method
Message(len::Integer)Create a message with a given buffer size (for send).
ZMQ.Message — Method
Message(origin::Any, m::Ptr{T}, len::Integer) where {T}Low-level function to create a message (for send) with an existing data buffer, without making a copy. The origin parameter should be the Julia object that is the origin of the data, so that we can hold a reference to it until ZMQ is done with the buffer.
ZMQ.Message — Method
Message(m::String)Create a message with a string as a buffer (for send). Note: the Message now "owns" the string, it must not be resized, or even written to after the message is sent.
ZMQ.Message — Method
Message(p::SubString{String})Create a message with a sub-string as a buffer (for send). Note: the same ownership semantics as for Message(m::String) apply.
ZMQ.Message — Method
Message(a::T) where T <: DenseVectorCreate a message with an array as a buffer (for send). Note: the same ownership semantics as for Message(m::String) apply.
Usually a will be a 1D Array/Vector, but on Julia 1.11+ it can also be a Memory.
ZMQ.Message — Method
Message(io::IOBuffer)Create a message with an IOBuffer as a buffer (for send). Note: the same ownership semantics as for Message(m::String) apply.
ZMQ.isfreed — Method
isfreed(m::Message)Check whether zeromq has called our free-function, i.e. whether we are safe to reclaim ownership of any buffer object the Message was created with.
Polling
ZMQ.Poller — Type
A Poller can wait on multiple sockets simultaneously for them to be ready for reading or writing.
Examples
poller = Poller([sock1, sock2])
while true
try
result::PollResult = wait(poller; timeout=0.1)
if ZMQ.recv(result.socket, String) == "exit"
break
end
catch ex
if !isa(ex, ZMQ.TimeoutError)
rethrow()
end
end
end
close(poller)ZMQ.Poller — Method
Poller(sockets::Vector{Socket})Create a Poller that monitors read events (ZMQ_POLLIN) for the given sockets.
ZMQ.Poller — Method
Poller(items::Vector{PollItem})Create a Poller from PollItem's. This offers the most flexibility since you can specify which events to monitor for each socket.
ZMQ.Poller — Method
Poller(f::Function, args)Do-constructor that will call f(poller) and clean up the Poller afterwards.
Base.wait — Method
wait(poller::Poller; timeout::Real=-1) -> PollResultWait for an event on one of the sockets monitored by poller and return a PollResult.
This function is not threadsafe, you must not call it multiple times concurrently. It is also not threadsafe to use any of the sockets being monitored while the function is executing.
Throws
ArgumentError: ifpolleris closed.TimeoutError: if a positivetimeoutis given and an event is not received in time.ErrorException: if the poller was closed while waiting.
Base.close — Method
close(poller::Poller)Close a Poller. It does not close the pollers sockets. This function is threadsafe and can be called at any time.
ZMQ.PollItem — Type
PollItem(socket::Socket; readable=true, writable=false)This object can be passed to a Poller to indicate whether the poller should wait for socket to become readable (ZMQ_POLLIN) or writable (ZMQ_POLLOUT).
ZMQ.PollResult — Type
This object represents an event on a socket. It's returned by wait(::Poller).
The fields are:
socket::Socketreadable::Boolwritable::Bool
Context
ZMQ.context — Function
context()Return the default ZMQ context (of type Context), initializing it if this has not been done already. (This context is automatically closed when Julia exits.)