ZeroRPC.NET
0.1.0
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
<PackageReference Include="ZeroRPC.NET" Version="0.1.0" />
<PackageVersion Include="ZeroRPC.NET" Version="0.1.0" />
<PackageReference Include="ZeroRPC.NET" />
paket add ZeroRPC.NET --version 0.1.0
#r "nuget: ZeroRPC.NET, 0.1.0"
#:package ZeroRPC.NET@0.1.0
#addin nuget:?package=ZeroRPC.NET&version=0.1.0
#tool nuget:?package=ZeroRPC.NET&version=0.1.0
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
voidandTask.
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:
- Client: Sends requests to the server using a
DealerSocket. - Server: Listens for incoming requests using a
RouterSocket. - Attributes: Define namespaces, methods, and execution rules for remote calls.
- Serialization: Arguments and responses are serialized using JSON.
- Fire & Forget: Do not wait for response for the methods that has return type of "void" or "Task"
- 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.
Links
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 | Versions 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. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection (>= 9.0.3)
- NetMQ (>= 4.0.1.13)
- System.Text.Json (>= 9.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.