Galosys.Foundation.DotNetty.Client 26.9.16.1

dotnet add package Galosys.Foundation.DotNetty.Client --version 26.9.16.1
                    
NuGet\Install-Package Galosys.Foundation.DotNetty.Client -Version 26.9.16.1
                    
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="Galosys.Foundation.DotNetty.Client" Version="26.9.16.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Galosys.Foundation.DotNetty.Client" Version="26.9.16.1" />
                    
Directory.Packages.props
<PackageReference Include="Galosys.Foundation.DotNetty.Client" />
                    
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 Galosys.Foundation.DotNetty.Client --version 26.9.16.1
                    
#r "nuget: Galosys.Foundation.DotNetty.Client, 26.9.16.1"
                    
#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 Galosys.Foundation.DotNetty.Client@26.9.16.1
                    
#: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=Galosys.Foundation.DotNetty.Client&version=26.9.16.1
                    
Install as a Cake Addin
#tool nuget:?package=Galosys.Foundation.DotNetty.Client&version=26.9.16.1
                    
Install as a Cake Tool

Galosys.Foundation.DotNetty.Client

成熟度: 🔴 实验性 — 依赖 preview 版本,API 可能变更

⚠️ 本模块依赖 preview/不稳定版本包,API 可能随时变更。

简介

基于 DotNetty 的高性能 RPC 客户端框架,提供声明式服务调用、自动代理生成、断线重连等功能,简化微服务间远程调用。

特性

  • 声明式 RPC 调用,通过接口定义远程服务
  • 自动代理生成,无需手动编写客户端代码
  • 内置断线重连机制,指数退避策略
  • 连接池管理,支持多服务实例负载均衡
  • 基于 DotNetty 的高性能异步通信
  • 统一响应格式 UnifiedResponse

安装

dotnet add package Galosys.Foundation.DotNetty.Client

配置

appsettings.json 中添加服务配置:

{
  "Services": {
    "IUserService": [
      "netty://localhost:8080"
    ]
  }
}

使用

定义远程服务接口

[NettyService("IUserService")]
public interface IUserService
{
    Task<UnifiedResponse> GetByIdAsync(int id);
    Task<UnifiedResponse> GetAllAsync();
}

注册服务

// Program.cs 或 Startup.cs
services.AddRpcClient();

调用远程服务

// 注入服务接口
private readonly IUserService _userService;

// 直接调用,自动代理转发到远程服务器
var response = await _userService.GetByIdAsync(1);

if (response.Code == "200")
{
    var user = response.Data;
    Console.WriteLine($"用户: {user.Name}");
}

多实例负载均衡

{
  "Services": {
    "IUserService": [
      "netty://server1:8080",
      "netty://server2:8080",
      "netty://server3:8080"
    ]
  }
}

核心类

说明
NettyRpcClient RPC 客户端核心类,管理连接和消息收发
RpcClientHandler 响应处理器,解析服务端返回结果
ConnectionWatchdogHandler 连接监视器,提供断线重连(最多3次,指数退避)
NettyRpcClientProxy 动态代理类,拦截接口方法调用转发到远程
NettyClientFactory 客户端工厂,管理客户端连接池
RpcClientServiceCollectionExtensions DI 扩展方法,注册 RPC 客户端服务

依赖

  • Galosys.Foundation.DotNetty - DotNetty 基础库(提供编解码、协议定义等)
  • Galosys.Foundation.Core - 核心库(提供 UnifiedResponseServiceProxy 等)

注意事项

  • 远程服务接口方法必须返回 Task<UnifiedResponse>
  • 使用 [NettyService] 特性标记接口,指定服务名称
  • 断线重连最多尝试 3 次,间隔按 2^n 秒递增
  • 服务地址从配置文件 Services:{ServiceName} 节点读取
  • 当前版本从地址列表取第一个地址连接(负载均衡待实现)
Product 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. 
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
26.9.16.1 38 9/16/2026
26.9.15.1 56 9/15/2026
26.9.14.1 77 9/14/2026
26.9.10.1 88 9/10/2026
26.9.3.1 87 9/3/2026
26.8.29.1 87 8/31/2026
26.8.26.1 86 8/26/2026
26.8.23.1 98 8/23/2026
26.8.21.1 92 8/21/2026
26.8.20.1 95 8/20/2026
26.8.18.1 102 8/18/2026
26.8.17.1 100 8/17/2026
26.8.13.2 98 8/13/2026
26.8.13.1 97 8/13/2026
26.8.12.2 102 8/12/2026
26.8.12.1 95 8/12/2026
26.8.10.1 97 8/10/2026
26.8.5.1 98 8/5/2026
26.8.4.1 108 8/4/2026
26.8.3.1 107 8/3/2026
Loading failed