The netzmq project contains .NET bindings for ZeroMQ, an open-source, high performance transport layer.
The project provides an idiomatic, test-friendly API and targets the Any CPU platform, which allows it to work seamlessly in heterogeneous deployment environments. Everything needed to write ZeroMQ programs is bundled in the netzmq assembly for both 32- and 64-bit platforms, including the native ZeroMQ libraries themselves (currently targeting version 3.0).
NOTE: These are not the official .NET bindings. Until this project is stable, you should use the official bindings, which are also available via NuGet.
There are three ways to use netzmq, listed below in order of preference:
- Add a reference to the NuGet package
- Download the lastest release from the Downloads tab
- Clone the source and build the project from scratch (see Build Instructions below)
// Client socket
using (var ctx = ZmqContext.Create())
using (var requestSocket = ctx.CreateRequestSocket())
{
requestSocket.Connect("tcp://127.0.0.1:9001");
requestSocket.Send("Hello world!".ToZmqBuffer());
}
// Server socket
using (var ctx = ZmqContext.Create())
using (var replySocket = ctx.CreateReplySocket())
{
replySocket.Bind("tcp://*:9001");
ReceivedMessage msg = replySocket.Receive();
Console.WriteLine("Message received: {0}", msg);
}
- Full API documentation and examples
- Add Mono support
This project currently depends on libzmq 3.0. In order to build netzmq, the build output from libzmq must be placed in the solution hierarchy. A rough guide follows:
- Clone libzmq
- Open builds\msvc\msvc.sln in Visual Studio
- Set the solution build configuration to Release/x86
- Build the
libzmq
project - Copy
builds\msvc\Release\libzmq.{dll,exp,lib}
tolib\x86
in your netzmq repository - Repeat steps 3-5 using the Release/x64 configuration, copying to
lib\x64
- Copy
include\zmq.h
toinclude
in your netzmq repository - Run
build.cmd
To include OpenPGM support, extract the included libpgm tarball to a path inside libzmq and perform the above steps using WithOpenPGM
as the build configuration instead of Release
. Project and library reference paths will need to be updated to reflect the OpenPGM extract path.
NOTE: The netzmq build scripts currently assume a 64-bit build environment.
This project is first and foremost a means to learn ZeroMQ more deeply. While there are other projects that provide .NET bindings for ZeroMQ, the secondary goals of this project are sufficiently different to justify creating a new library, at least for experimentation. If any of the ideas in this project appeal to the maintainers of other bindings, I'd be happy to collaborate on patches.
- clrzmq2 (still maintained)
- ZeroMQ Interop (actively developed)
- NZMQ (last updated 2010)
netzmq is released under the Apache 2.0 license. See LICENSE and NOTICE for details.