.NET bindings to NNG:
NNG, like its predecessors nanomsg (and to some extent ZeroMQ), is a lightweight, broker-less library, offering a simple API to solve common recurring messaging problems, such as publish/subscribe, RPC-style request/reply, or service discovery. The API frees the programmer from worrying about details like connection management, retries, and other common considerations, so that they can focus on the application instead of the plumbing.
Status:
Using latest NNG release.
For list of missing APIs/features see issues (is:open label:enhancement
).
Goals of nng.NET:
dotnet
and targeting .NET Standard and .NET Core/5 from the startnull
, type system avoids many runtime errors at compile time.Supports projects targeting:
SuppressUnmanagedCodeSecurity
is used with .NET Standard 2.0+ for improved PInvoke performanceShould be easy to add others that are supported by both .NET Core/5 and NNG.
After installing the package and building, your output folder should have runtimes/
directory containing native binaries.
Use NngLoadContext
(or your own AssemblyLoadContext
) to load the appropriate native library and use NNG:
var path = Path.GetDirectoryName(typeof(Program).Assembly.Location);
var ctx = new nng.NngLoadContext(path);
var factory = nng.NngLoadContext.Init(ctx);
// Use factory...
See tests/
and examples/
for usage examples.
You should be able to build nng.NET for/on any platform supported by .NET Core/5:
dotnet build
dotnet run
or dotnet test tests
You should be able to build the NNG native shared library for any platform supported by NNG. See scripts/build_nng.ps1
for details, but in general:
vcvars64.bat
in cmd.exe (or vcvars32.bat
)mkdir build && cd build
cmake -DBUILD_SHARED_LIBS=ON ..
cmake --build .
nng.NET/runtimes/XXX/native/
)