A pure-Go implementation of the ZeroMQ socket patterns and the ZMTP 3.1 wire
protocol. No cgo, no libzmq, no build tags — CGO_ENABLED=0 go build just
works, everywhere the Go toolchain does.
It is actually CGO-free. The popular Go binding, pebbe/zmq4, wraps
libzmq through cgo: you inherit a C build dependency, lose cross-compilation,
and pay a cgo transition on every call. gozmq is Go all the way down. The
only cgo in this repository is the build-tagged interop test harness that
checks us against a real libzmq.
It talks to libzmq. Wire compatibility is a first-class goal, not an
aspiration. CI runs the interop/ suite against libzmq 4.3.x in
both directions; the matrix is in interop/README.md.
It is fast enough that the tradeoff is gone. Measured two-process over
TCP loopback against native libzmq 4.3.4 (PUSH/PULL, October 2026) at Go's
default runtime settings, gozmq is at or ahead of libzmq at every size:
1.3–1.6× at 32 B, 1.0–1.1× at 1 KB, 1.3–2.1× at 64 KB, where large
received frames come from a recycling buffer pool by default
(Release gives them back; WithRecvBufferPool(false) opts out). REQ/REP
round trips over TCP are 20% shorter than libzmq's, and inproc delivery is
1.5× libzmq's at 32 B. The numbers, the method
and the tools to reproduce them are in perf/REPORT.md.
Requires Go 1.25 or newer.
go get github.com/exergy-dev/gozmqctx := gozmq.NewContext()
defer ctx.Close()
server, _ := ctx.NewSocket(gozmq.Pair)
defer server.Close()
_ = server.Bind("inproc://hello")
client, _ := ctx.NewSocket(gozmq.Pair)
defer client.Close()
_ = client.Connect("inproc://hello")
callCtx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
_ = client.SendBytes(callCtx, []byte("ping"))
msg, _ := server.RecvBytes(callCtx)
fmt.Printf("%s\n", msg) // pingEvery blocking call takes a context.Context — there is no SNDTIMEO or
RCVTIMEO to configure, because cancellation and deadlines are already
Go's job.
Proxy is the zmq_proxy equivalent, and the XSUB/XPUB device is what most
deployments eventually need — publishers connect to one stable address,
subscribers to another, and either side can churn freely:
xsub, _ := ctx.NewSocket(gozmq.XSub)
_ = xsub.Connect("tcp://publisher.internal:5555")
xpub, _ := ctx.NewSocket(gozmq.XPub)
_ = xpub.Bind("tcp://*:5556")
// Subscriptions travel upstream through the proxy on their own.
// Pass a fourth socket instead of nil to tap the traffic.
if err := gozmq.Proxy(ctx.Ctx(), xsub, xpub, nil); err != nil {
log.Fatal(err)
}- Socket types:
REQ,REP,DEALER,ROUTER,PUB,SUB,XPUB,XSUB,PUSH,PULL,PAIR,STREAM. - Transports:
tcp://,tcp6://,ipc://,inproc://, andtls+tcp://(gozmq-specific — libzmq has no TLS transport). Third-party transports are a supported extension point. - Security: NULL, PLAIN, CURVE, and RFC 27 ZAP.
- Operations: reconnect with exponential backoff and jitter, ZMTP 3.1
heartbeats, high-water marks, cancellable linger, live
Unbind/Disconnect/Subscribe, monitor events, per-socket metrics, andslogintegration. - Ergonomics:
Pollerforzmq_poll-style multiplexing,Proxyfor devices,SendBytes/RecvBytesfor single-frame payloads, and a generictypedlayer for codec-backed messages.
For the precise inventory — including what is not implemented and every place behaviour differs from libzmq — see docs/COMPATIBILITY.md.
Semantic versioning, pre-1.0: a 0.x minor may break the API, and every such
change is listed in CHANGELOG.md with a migration hint. From v1.0.0 the
compatibility promise covers everything exported outside internal/.
The default mechanism is NULL: no authentication, no encryption, matching
libzmq. Use CURVE, or PLAIN under tls+tcp://, on anything but trusted
segments. The PLAIN and CURVE server/client role comes from the option
(WithPlainAuth / WithPlainClient, WithCurveServer / WithCurveClient),
not from which side binds, and a CURVE server authorizes nobody until a
security.ZAPHandler is installed with gozmq.WithZAPHandler. Message
ownership, inproc:// and STREAM semantics are in the package
documentation and docs/COMPATIBILITY.md.
- API reference — pkg.go.dev. The package doc covers security, defaults, STREAM, polling, close semantics, and the concurrency model.
- libzmq compatibility —
docs/COMPATIBILITY.md. - Runnable demos —
examples/, plus theExample*functions in the package tests. - Architecture —
design.md. - Performance —
perf/REPORT.mdand the libzmq-comparable tool inperf/. - Contributing —
CONTRIBUTING.md. - Security policy —
SECURITY.md.
MIT — see LICENSE.