Skip to content

awesomedotnetcore/nng.NETCore

 
 

Repository files navigation

nng.NETCore

.NET Core 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:

Beta-ish. Using latest NNG release (currently v1.1.1). Once this is a bit farther along will track NNG version numbers.

NuGet Build status Build status codecov

For list of missing APIs/features see is:issue is:open label:enhancement.

Goals of nng.NETCore:

  • Async first: async/await access to nng_aio and nng_ctx
  • Native layer: P/Invoke in separate files/namespace. Don't like our high-level OO wrapper? Re-use the pinvoke and make your own. Also makes cross-platform-friendly pinvoke easier.
  • Tests as Documentation: xUnit unit/integration tests in "plain" C# much like you'd write
  • .NET Core friendly: Using dotnet and targetting .NET Standard from the start
  • Few surprises: Simple class heirarchy (more composition than inheritance), minimal exceptions, idiomatic C# that when reasonable is similar to original native code

Usage

Supports projects targetting:

Supported platforms:

  • Windows Vista or later 32/64-bit
  • macOS/OSX 10.?+ (built on 10.14)
  • Linux 64-bit (built on Ubuntu 18.04)

Should be easy to add others that are supported by both .NET Core and NNG.

After installing the package and building, your output folder should have runtimes/ directory containing native binaries.

On .NET Core/Standard 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/ for basic examples.

Build & Run

You should be able to build nng.NETCore for/on any platform supported by .NET Core:

  1. Build: dotnet build
  2. Run: dotnet run or dotnet test tests

You should be able to build the NNG native shared library for any platform supported by NNG:

  1. Download/clone NNG source
  2. On Windows, create Command Prompt suitable for Visual Studio:
    • Run x64 Visual Studio Developer Command Prompt to create a 64-bit library (or x86 for 32-bit)
    • OR, run vcvars64.bat in cmd.exe (or vcvars32.bat)
  3. Make sure cmake and Ninja are in PATH environment variable
  4. Run:
    mkdir build && cd build
    cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release ..
    ninja
    
  5. Copy library to appropriate nng.NETCore/runtimes/XXX/native/ directory

.NET Framework

System.Runtime.Loader is not available in .NET Framework, so the correct assembly must be loaded by some other means.

If your application is targetting .Net Framework 4.6+ and you get lots of:

message NETSDK1041: Encountered conflict between 'Reference:XXX\.nuget\packages\subor.nng.netcore\0.0.5\lib\netstandard2.0\Microsoft.Win32.Primitives.dll' and 'Reference:Microsoft.Win32.Primitives'.  NETSDK1034: Choosing 'Reference:XXX\.nuget\packages\subor.nng.netcore\0.0.5\lib\netstandard2.0\Microsoft.Win32.Primitives.dll' because file version '4.6.26419.2' is greater than '4.6.25714.1'.

<snip>

XXX\Properties\AssemblyInfo.cs(8,12,8,25): error CS0246: The type or namespace name 'AssemblyTitleAttribute' could not be found (are you missing a using directive or an assembly reference?)

Try adding the following to your project:

<PropertyGroup>
    <DependsOnNETStandard>false</DependsOnNETStandard>
</PropertyGroup>

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%