(Formerly clrzmq2; legacy bindings have moved to clrzmq-old)
This project aims to provide the full functionality of the underlying ZeroMQ API to CLR projects.
Bundled libzmq version: 3.2.2-rc2
Legacy libzmq version supported: 2.2.0 (stable)
The quickest way to get started with clrzmq is by using the NuGet package. The NuGet packages include a copy of the native libzmq.dll, which is required to use clrzmq.
You may also build clrzmq directly from the source. See the Development Environment Setup instructions below for more detail.
To get an idea of how to use clrzmq, have a look at the following example.
using System;
using System.Text;
using System.Threading;
using ZMQ;
namespace ZMQGuide
{
class Program
{
static void Main(string[] args)
{
// ZMQ Context, server socket
using (ZmqContext context = ZmqContext.Create())
using (ZmqSocket server = context.CreateSocket(SocketType.REP))
{
server.Bind("tcp://*:5555");
while (true)
{
// Wait for next request from client
string message = server.Receive(Encoding.Unicode);
Console.WriteLine("Received request: {0}", message);
// Do Some 'work'
Thread.Sleep(1000);
// Send reply back to client
server.Send("World", Encoding.Unicode);
}
}
}
}
}
using System;
using System.Text;
using ZMQ;
namespace ZMQGuide
{
class Program
{
static void Main(string[] args)
{
// ZMQ Context and client socket
using (ZmqContext context = ZmqContext.Create())
using (ZmqSocket client = context.CreateSocket(SocketType.REQ))
{
client.Connect("tcp://localhost:5555");
string request = "Hello";
for (int requestNum = 0; requestNum < 10; requestNum++)
{
Console.WriteLine("Sending request {0}...", requestNum);
client.Send(request, Encoding.Unicode);
string reply = client.Receive(Encoding.Unicode);
Console.WriteLine("Received reply {0}: {1}", requestNum, reply);
}
}
}
}
}
For more information about 0MQ and clrzmq, see the following resources:
More tutorials and API documentation are on the way.
When using a packaged (NuGet/zip) release on Windows, clrzmq comes bundled with 32- and 64-bit versions of libzmq.dll that have been fully tested with the binding package. The DLLs are embedded as manifest resources in the assembly and are extracted when initially loading the assembly. To accommodate different deployment needs, several output paths may be used.
The libzmq.dll search/extract order is as follows:
%TEMP%\clrzmq-x.x.x.x
If you run into problems related to loading the native library, you can enable tracing in your application as follows:
clrzmq
trace switch to use the Info
level (3):<configuration>
<system.diagnostics>
<switches>
<add name="clrzmq" value="3" /><!-- Info -->
</switches>
</system.diagnostics>
</configuration>
IIS deployments can be complicated due to the many possible identities and privilege levels that may be executing your application. There are a few steps you can take to ensure the bundled native libraries can be properly extracted and used:
%TEMP%
folderbin
directory (i.e., the directory containing clrzmq.dll and your application assemblies)On Windows/.NET, clrzmq is developed with Visual Studio 2010. Mono development is done with MonoDevelop 2.8+.
clrzmq depends on libzmq.dll
, which will be retrieved automatically via NuGet. If you require a specific version of libzmq, you can compile it from the 0MQ sources.
build.cmd
to build the project and run the test suite./build
.If you want to use a custom build of libzmq.dll
, perform the following steps:
src/.nuget/packages.config
file. This prevent the NuGet package from being retrieved.src/packages/libzmq-*
that may have been downloaded previously.libzmq.dll
to lib/x86
and lib/x64
, respectively.Note that PGM-related tests will fail if a non-PGM build of libzmq is used.
NOTE: Mono 2.10.7+ is required for development only, as the NuGet scripts and executables require this version to be present. If you choose to install dependencies manually, you may use any version of Mono 2.6+.
NuGet relies on several certificates to be registered with Mono. The following is an example terminal session (on Ubuntu) for setting this up correctly. This assumes you have already installed Mono 2.10.7 or higher.
$ mozroots --import --sync
$ certmgr -ssl https://go.microsoft.com
$ certmgr -ssl https://nugetgallery.blob.core.windows.net
$ certmgr -ssl https://nuget.org
This should result in a working Mono setup for use with NuGet.
Either clone the ZeroMQ repository or download the sources, and then follow the build/install instructions for your platform.
Use the --with-pgm
option if possible.
nuget.sh
, which downloads any dependent packages (e.g., NUnitLite for acceptance tests).make
to build the project and run the test suite./build
.NOTE: clrzmq
only supports x86 builds on Mono at this time
Issues should be logged on the GitHub issue tracker for this project.
When reporting issues, please include the following information if possible:
Pull requests and patches are always appreciated! To speed up the merge process, please follow the guidelines below when making a pull request:
Pull requests will still be accepted if some of these guidelines are not followed: changes will just take longer to merge, as the missing pieces will need to be filled in.
This project is released under the LGPL license, as is the native libzmq library. See LICENSE for more details as well as the 0MQ Licensing page.