You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.2 KiB

using System.ComponentModel.DataAnnotations;
namespace CoreAgent.WebSocketTransport.Models;
/// <summary>
/// WebSocket 客户端配置模型
/// 支持通过 IConfiguration 绑定,提供合理的默认值
/// </summary>
public class WebSocketConfig
{
/// <summary>
/// WebSocket 服务器地址
/// </summary>
[Required(ErrorMessage = "WebSocket URL 不能为空")]
[Url(ErrorMessage = "WebSocket URL 格式不正确")]
public string Url { get; set; } = "wss://example.com/ws";
/// <summary>
/// 连接超时时间(毫秒)
/// </summary>
[Range(1000, 300000, ErrorMessage = "超时时间必须在 1000-300000 毫秒之间")]
public int TimeoutMs { get; set; } = 30000;
/// <summary>
/// 批量发送时间窗口(毫秒)
/// </summary>
[Range(10, 10000, ErrorMessage = "批量超时时间必须在 10-10000 毫秒之间")]
public int BatchTimeoutMs { get; set; } = 100;
/// <summary>
/// 最大批量大小(条消息)
/// </summary>
[Range(1, 10000, ErrorMessage = "最大批量大小必须在 1-10000 之间")]
public int MaxBatchSize { get; set; } = 100;
/// <summary>
/// 是否启用自动重连功能
/// </summary>
public bool EnableAutoReconnect { get; set; } = true;
/// <summary>
/// 最大重连尝试次数
/// </summary>
[Range(0, 100, ErrorMessage = "最大重连次数必须在 0-100 之间")]
public int MaxReconnectAttempts { get; set; } = 5;
/// <summary>
/// 队列容量(已废弃,请使用 SendChannelCapacity、ReceiveChannelCapacity、PriorityChannelCapacity)
/// </summary>
[Range(10, 100000, ErrorMessage = "队列容量必须在 10-100000 之间")]
public int QueueCapacity { get; set; } = 10000;
/// <summary>
/// 发送通道容量
/// </summary>
[Range(10, 100000, ErrorMessage = "发送通道容量必须在 10-100000 之间")]
public int SendChannelCapacity { get; set; } = 1000;
/// <summary>
/// 接收通道容量
/// </summary>
[Range(10, 100000, ErrorMessage = "接收通道容量必须在 10-100000 之间")]
public int ReceiveChannelCapacity { get; set; } = 1000;
/// <summary>
/// 优先级通道容量
/// </summary>
[Range(10, 10000, ErrorMessage = "优先级通道容量必须在 10-10000 之间")]
public int PriorityChannelCapacity { get; set; } = 100;
/// <summary>
/// 缓存消息 TTL(分钟)
/// </summary>
[Range(1, 1440, ErrorMessage = "缓存 TTL 必须在 1-1440 分钟之间")]
public int CacheTtlMinutes { get; set; } = 5;
/// <summary>
/// 最大分包大小(字节),超过此大小的消息将被分包发送
/// 建议值:32KB-128KB,默认64KB
/// </summary>
[Range(1024, 1024 * 1024, ErrorMessage = "分包大小必须在 1KB-1MB 之间")]
public int? MaxChunkSize { get; set; } = 64 * 1024; // 64KB
/// <summary>
/// 分包发送延迟(毫秒),用于控制分包发送的速率
/// 建议值:1-10ms,默认1ms
/// </summary>
[Range(0, 100, ErrorMessage = "分包延迟必须在 0-100 毫秒之间")]
public int? ChunkDelayMs { get; set; } = 1;
}