Scripts2026年9月11日·1 分钟阅读

nanomsg — Socket Library for Scalable Messaging Patterns

Build distributed systems with a simple C library that provides common messaging patterns like pub/sub, request/reply, and pipeline.

Agent 就绪

Agent 可直接安装

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

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

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

Introduction

nanomsg is a socket library written in C that provides several common communication patterns for building distributed systems. Created by Martin Sustrik (co-creator of ZeroMQ), it simplifies inter-process and network messaging with a POSIX-like API and built-in scalability protocols.

What nanomsg Does

  • Implements messaging patterns: PAIR, PIPELINE, REQ/REP, PUB/SUB, SURVEY, and BUS
  • Works over TCP, IPC (Unix sockets), in-process, and WebSocket transports
  • Provides automatic reconnection and load balancing across endpoints
  • Handles message framing, routing, and delivery semantics per protocol
  • Exposes a simple BSD socket-like C API (nn_socket, nn_send, nn_recv)

Architecture Overview

nanomsg uses a layered architecture with transports at the bottom (TCP, IPC, inproc, WebSocket) and scalability protocols on top. Each protocol defines its own routing and delivery semantics. The library runs an internal I/O thread pool that manages connections and message queuing asynchronously. The public API is synchronous by default with non-blocking options available via nn_poll or socket options.

Self-Hosting & Configuration

  • Build from source with CMake or install via system package managers
  • Link against libnanomsg in your C/C++ project with -lnanomsg
  • Set socket options for buffer sizes, timeouts, and reconnect intervals via nn_setsockopt
  • Bind a socket to listen on an address, or connect to a remote endpoint
  • Language bindings exist for Python, Go, Rust, Java, Ruby, Node.js, and more

Key Features

  • Seven built-in scalability protocols covering most messaging patterns
  • Transport-agnostic: switch between TCP, IPC, and inproc by changing the address string
  • Automatic reconnection on connection loss with configurable retry intervals
  • Zero-copy message API for high-throughput scenarios
  • Clean C API with no external dependencies beyond the C standard library

Comparison with Similar Tools

  • ZeroMQ — more mature ecosystem with more patterns and language bindings; nanomsg offers a cleaner API and pluggable transports
  • nng — the spiritual successor to nanomsg by the same author, with an async-first API
  • gRPC — RPC framework with code generation; nanomsg provides raw messaging patterns
  • NATS — server-based pub/sub; nanomsg is a brokerless peer-to-peer library

FAQ

Q: What is the difference between nanomsg and nng? A: nng (nanomsg-next-gen) is the successor project with a redesigned async API and better scalability. nanomsg remains stable and widely deployed.

Q: Does nanomsg require a message broker? A: No. nanomsg is fully brokerless. Peers connect directly to each other.

Q: Which transport should I use for local IPC? A: Use ipc:// for inter-process on the same host or inproc:// for threads within the same process.

Q: What license does nanomsg use? A: MIT license.

Sources

讨论

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

相关资产