Skills2026年4月13日·1 分钟阅读

ZeroMQ — High-Performance Asynchronous Messaging Library

ZeroMQ (0MQ) is a high-performance asynchronous messaging library for distributed applications. It provides socket-like abstractions for message passing patterns — pub/sub, request/reply, push/pull — without the complexity of a full message broker.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
step-1.md
直接安装命令
npx -y tokrepo@latest install 8dae1416-3734-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

TL;DR
ZeroMQ provides brokerless message passing with pub/sub, request/reply, and push/pull patterns.
§01

What it is

ZeroMQ (0MQ) is a high-performance asynchronous messaging library for distributed applications. It provides socket-like abstractions for common message passing patterns -- publish/subscribe, request/reply, push/pull, and dealer/router. Unlike Kafka or RabbitMQ, ZeroMQ requires no message broker; peers communicate directly.

ZeroMQ is for systems programmers and backend engineers building distributed applications that need fast, lightweight messaging without the operational overhead of a broker.

The project is actively maintained with regular releases and a growing user community. Documentation covers common use cases, and the open-source nature means you can inspect the source code, contribute fixes, and adapt the tool to your specific requirements.

§02

How it saves time or tokens

Broker-based messaging systems add infrastructure complexity and latency. ZeroMQ embeds directly into your application as a library, eliminating the broker entirely. Setup is one pip/npm/cargo install. Messages flow peer-to-peer with microsecond latency and millions of messages per second throughput.

§03

How to use

  1. Install the ZeroMQ library for your language.
  2. Create a socket with the desired pattern (PUB, SUB, REQ, REP, PUSH, PULL).
  3. Bind or connect the socket and start sending/receiving messages.
§04

Example

import zmq

# Publisher
context = zmq.Context()
pub = context.socket(zmq.PUB)
pub.bind('tcp://*:5555')
pub.send_string('topic hello world')

# Subscriber (separate process)
context = zmq.Context()
sub = context.socket(zmq.SUB)
sub.connect('tcp://localhost:5555')
sub.setsockopt_string(zmq.SUBSCRIBE, 'topic')
message = sub.recv_string()
print(message)  # 'topic hello world'
# Install
pip install pyzmq     # Python
npm install zeromq    # Node.js
brew install zeromq   # C library (macOS)
§05

Related on TokRepo

§06

Common pitfalls

  • ZeroMQ PUB/SUB drops messages if the subscriber connects after the publisher starts sending. Use a synchronization mechanism or a XPUB/XSUB proxy for reliable subscription.
  • ZeroMQ sockets are not thread-safe. Each thread must create its own context and sockets. Sharing sockets across threads causes undefined behavior.
  • There is no message persistence. If a consumer is offline, messages are lost. For durable messaging, use ZeroMQ with an application-level persistence layer or switch to NATS JetStream.

Before adopting this tool, evaluate whether it fits your team's existing workflow. Read the official documentation thoroughly, and start with a small proof-of-concept rather than a full migration. Community forums, GitHub issues, and Stack Overflow are valuable resources when you encounter edge cases not covered in the documentation.

常见问题

How is ZeroMQ different from RabbitMQ?+

RabbitMQ is a message broker that stores and routes messages centrally. ZeroMQ is a library that provides socket abstractions for direct peer-to-peer messaging. ZeroMQ has lower latency and no infrastructure to manage, but lacks built-in persistence and routing.

What messaging patterns does ZeroMQ support?+

ZeroMQ supports pub/sub, request/reply, push/pull (pipeline), dealer/router (async request/reply), pair, and exclusive pair. Each pattern is implemented as a socket type with specific send/receive semantics.

Which programming languages have ZeroMQ bindings?+

ZeroMQ has bindings for Python (pyzmq), C/C++, Java (JeroMQ), Node.js, Go, Rust, C#, Ruby, and many others. The core library is written in C++ with a stable C API.

Does ZeroMQ support encryption?+

Yes. ZeroMQ supports CurveZMQ encryption using elliptic-curve cryptography. Configure public/private key pairs on sockets for authenticated, encrypted communication.

Is ZeroMQ suitable for microservices?+

Yes, for services that need low-latency direct communication. ZeroMQ works well for internal service-to-service messaging where broker overhead is undesirable. For external-facing APIs or durable messaging, pair it with an API gateway or persistence layer.

引用来源 (3)

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产