ZeroRPC.NET 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ZeroRPC.NET --version 0.1.0
                    
NuGet\Install-Package ZeroRPC.NET -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZeroRPC.NET" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroRPC.NET" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ZeroRPC.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZeroRPC.NET --version 0.1.0
                    
#r "nuget: ZeroRPC.NET, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ZeroRPC.NET@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZeroRPC.NET&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ZeroRPC.NET&version=0.1.0
                    
Install as a Cake Tool

ZeroRPC for .NET

ZeroRPC is a .NET library designed to enable seamless communication between multiple applications using the ZeroMQ Dealer-Router pattern. It provides an elegant, attribute-based approach to defining remote methods and namespaces, making it easy to invoke server-side methods directly from client applications via interfaces.

This library offering lightweight, fast, and customizable Remote Procedure Call (RPC) functionality. With ZeroRPC, developers can focus on building distributed systems without worrying about the complexities of communication protocols.


Features

  • Attribute-Based RPC: Use [RemoteMethod], [RemoteService], and [RemoteExecutionRule] attributes to define remote methods and namespaces.
  • ZeroMQ Dealer-Router Pattern: Leverages ZeroMQ for high-performance, asynchronous messaging.
  • Retry & Timeout Rules: Configure timeout and retry logic for remote method calls.
  • Seamless Integration: Easily integrate with .NET dependency injection for both clients and servers.
  • Task and Void Support: Automatically handles return types, including void and Task.

Installation

Install the library via NuGet:

dotnet add package ZeroRPC

Getting Started

1. Define Remote Interfaces and Methods

Use the [RemoteService] and [RemoteMethod] attributes to define your remote interfaces and methods.

[RemoteService("IMyService","MyApp")]
public interface IMyService
{
    [RemoteMethod("GetData")]
    [RemoteExecutionRule(timeoutMillisecond: 5000, retryCount: 3)]
    string GetData(int id);

    [RemoteMethod("SendMessage")]
    void SendMessage(string message);
}

2. Implement Server-Side Logic

Implement the interface on the server side.

public class MyService : IMyService
{
    public string GetData(int id)
    {
        return $"Data for ID: {id}";
    }

    public void SendMessage(string message)
    {
        Console.WriteLine($"Message received: {message}");
    }
}

3. Setup the Server

Register the server and bind it to a port.

var services = new ServiceCollection();
services.AddZeroRpcServer();
services.AddSingleton<IMyService, MyService>();

var serviceProvider = services.BuildServiceProvider();
serviceProvider.RegisterZeroRpcServices(port: 5555);

4. Setup the Client

Register the client and connect to the server.

var services = new ServiceCollection();
services.AddZeroRpcClient<IMyService>(port: 5555);

var serviceProvider = services.BuildServiceProvider();
var client = serviceProvider.GetRequiredService<IMyService>();

// Call remote methods
var data = client.GetData(42);
Console.WriteLine(data);

client.SendMessage("Hello, server!");

Advanced Features

Retry Logic and Timeout

Use [RemoteExecutionRule] to configure retries and timeouts for remote method calls.

[RemoteExecutionRule(timeoutMillisecond: 10000, retryCount: 5)]
string GetData(int id);

Exception Handling

ZeroRPC propagates server-side exceptions back to the client. You can handle exceptions as follows:

try
{
    var data = client.GetData(999);
}
catch (ZeroRpcException ex)
{
    Console.WriteLine($"RPC Error: {ex.Message}");
}

Example Code

Server

var services = new ServiceCollection();
services.AddZeroRpcServer();
services.AddSingleton<IMyService, MyService>();

var serviceProvider = services.BuildServiceProvider();
serviceProvider.RegisterZeroRpcServices(port: 5555);

Client

var services = new ServiceCollection();
services.AddZeroRpcClient<IMyService>(port: 5555);

var serviceProvider = services.BuildServiceProvider();
var client = serviceProvider.GetRequiredService<IMyService>();

var data = client.GetData(42);
Console.WriteLine(data);

client.SendMessage("Hello, server!");

How It Works

ZeroRPC uses the ZeroMQ Dealer-Router pattern for communication:

  1. Client: Sends requests to the server using a DealerSocket.
  2. Server: Listens for incoming requests using a RouterSocket.
  3. Attributes: Define namespaces, methods, and execution rules for remote calls.
  4. Serialization: Arguments and responses are serialized using JSON.
  5. Fire & Forget: Do not wait for response for the methods that has return type of "void" or "Task"
  6. Request TTL: Server doesn't process incoming requests if the timeout reached (client not listening for respnose anymore)

Contributing

Contributions are welcome! If you find a bug or want to add a feature, feel free to open an issue or submit a pull request.


License

ZeroRPC is licensed under the MIT License. See the LICENSE file for details.



Example Repository

Check out the example repository for a full implementation of ZeroRPC: ZeroRPC Example


Roadmap

  • Adding unit tests
  • Encapsulation for MQ library for further alternatives.
  • Add support for streaming RPC calls.
  • Improve error handling and logging.
  • Optimize serialization/deserialization performance.
  • Add more examples and documentation.

Feel free to copy and adapt this README for your GitHub repository!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 187 3/28/2025
0.2.0 200 3/26/2025
0.1.0 501 3/25/2025