RabbitRpc.Server
4.0.1
dotnet add package RabbitRpc.Server --version 4.0.1
NuGet\Install-Package RabbitRpc.Server -Version 4.0.1
<PackageReference Include="RabbitRpc.Server" Version="4.0.1" />
<PackageVersion Include="RabbitRpc.Server" Version="4.0.1" />
<PackageReference Include="RabbitRpc.Server" />
paket add RabbitRpc.Server --version 4.0.1
#r "nuget: RabbitRpc.Server, 4.0.1"
#:package RabbitRpc.Server@4.0.1
#addin nuget:?package=RabbitRpc.Server&version=4.0.1
#tool nuget:?package=RabbitRpc.Server&version=4.0.1
RabbitRpc.Server
Server-side library for RabbitMQ RPC on .NET 10. Register implementations of contract interfaces with DI; a hosted service listens on the configured RabbitMQ route and dispatches each incoming request to the matching method.
v4.0 introduces a pluggable serialization layer — you must pair this package with one of the adapter packages:
RabbitRpc.Serialization.XPacketRpc— binary, source-gen, recommended default.RabbitRpc.Serialization.MemoryPack— binary, MemoryPack-backed; works with vendor DTOs without[MemoryPackable].RabbitRpc.Serialization.SystemTextJson— JSON, for debugging and v3 wire compatibility.
Installation
dotnet add package RabbitRpc.Server
dotnet add package RabbitRpc.Serialization.XPacketRpc # or .MemoryPack / .SystemTextJson
Pack for NuGet
dotnet pack -c Release
Configuration
Add the RabbitMqRpc section to appsettings.json:
{
"RabbitMqRpc": {
"HostName": "localhost",
"Port": 5672,
"VirtualHost": "/",
"UserName": "guest",
"Password": "guest",
"ClientProvidedName": "rabbit-rpc-server",
"RoutePrefix": "rpc.",
"PrefetchCount": 1,
"ConsumerDispatchConcurrency": null,
"DefaultTimeoutSeconds": 30
}
}
ConsumerDispatchConcurrency defaults to PrefetchCount; handlers must be thread-safe when it is > 1. Set it to 1 for the v3.0 sequential-dispatch behaviour.
Usage
Define a contract interface (shared between client and server) and implement it on the server:
public interface IMathService
{
Task<int> AddAsync(int a, int b);
Task<UserDto> GetUserAsync(Guid id);
}
public sealed class MathService : IMathService
{
public Task<int> AddAsync(int a, int b) => Task.FromResult(a + b);
public Task<UserDto> GetUserAsync(Guid id) => Task.FromResult(new UserDto(id, "Alice"));
}
Register the server and handlers in Program.cs:
using AsbtCore.Broker.Server;
using AsbtCore.Broker.Serialization.XPacketRpc; // pick one adapter
var builder = Host.CreateApplicationBuilder(args);
builder.Services
.AddRabbitRpcServer(builder.Configuration) // returns RpcServerBuilder
.UseXPacketRpcSerialization() // required in v4.0
.Register<IMathService, MathService>();
await builder.Build().RunAsync();
The hosted service declares one durable queue per RPC route (rpc.<InterfaceFullName>), one companion dead-letter queue (<route>.dead), and starts consuming. Server-side exceptions are serialized and rethrown on the client as RpcRemoteException. Poison messages (deserialization failure, unresolvable type, dispatcher error) are routed to the DLQ after a single attempt — no requeue loops; monitor *.dead depth for alerting.
Migration v3.x → v4.0
| Was (v3.x) | Now (v4.0) |
|---|---|
AddRabbitRpcServer(cfg) returns RpcServerBuilder, defaults JSON |
returns RpcServerBuilder, NO default serializer |
services.AddRpcSerialization() |
builder.UseXxxSerialization() from an adapter package |
JsonElement result in RpcResponse |
ReadOnlyMemory<byte>? |
RpcRequestDispatcher ctor with 2 args |
ctor takes IRpcSerializer as a third parameter |
Startup throws OptionsValidationException with a helpful message if no IRpcSerializer is registered. See the repo migration guide for the full break list.
See Also
- RabbitRpc.Client — client-side library with typed proxies.
- RabbitRpc.Serialization.XPacketRpc — binary adapter (default since v4.0).
- RabbitRpc.Serialization.MemoryPack — MemoryPack binary adapter with reflection-friendly DTO discovery.
- RabbitRpc.Serialization.SystemTextJson — JSON adapter for v3 wire compatibility.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.8)
- Microsoft.Extensions.Options.DataAnnotations (>= 10.0.8)
- RabbitMQ.Client (>= 7.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v4.0.1 — Binary serialization. MINOR UPDATE.
- Wire format is incompatible with v3.x. Roll forward client and server together.
- A serialization adapter package is now REQUIRED: install either
RabbitRpc.Serialization.XPacketRpc (binary, default) or
RabbitRpc.Serialization.SystemTextJson (JSON, drop-in v3 compat shape).
- DI now requires '.UseXPacketRpcSerialization()' / '.UseJsonRpcSerialization()' on
the builder returned by 'AddRabbitRpcServer(cfg)'. Startup throws if missing.
- 'RpcRequest.Arguments[i].Payload' / 'RpcResponse.Result' changed from
'JsonElement' to 'ReadOnlyMemory<byte>'.
- 'IRpcSerializer' surface widened to four methods. Custom implementations must update.
See README "Migration v3.1 → v4.0".