sendqueue

package
v1.48.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package sendqueue provides an async message send queue with rate limiting.

Usage:

pm.Register(sendqueue.New(sendqueue.Config{Rate: 5, Burst: 10})) // In a Handler: sqSvc := ctx.Service[*sendqueue.Plugin]("sendqueue") sq.Enqueue("chat_id", platform.TextMessage("hello"), nil)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg Config) *plugin.Descriptor

New creates a send queue plugin descriptor.

Types

type Config

type Config struct {
	// Rate 全局消息发送速率(条/秒)
	Rate float64
	// Burst 令牌桶突发容量
	Burst int
	// PerTargetRate 单 target(群/用户)的速率(条/秒),0 表示不限
	PerTargetRate float64
	// PerTargetBurst 单 target 突发容量
	PerTargetBurst int
	// QueueSize 队列最大深度
	QueueSize int
	// Workers 消费 goroutine 数量
	Workers int
	// MaxRetries 发送失败最大重试次数
	MaxRetries int
	// RetryDelay 重试间隔
	RetryDelay time.Duration
}

Config holds configuration for the send queue plugin.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

Plugin is the send queue plugin API.

func (*Plugin) Enqueue

func (p *Plugin) Enqueue(chat platform.ChatInfo, msg platform.OutboundMessage, sender platform.Sender) error

Enqueue 将平台无关消息加入发送队列。

chat 指定目标会话(ID + IsGroup 路由信息),用于限流 key 和注入 ChatInfo。 若 sender 为 nil,使用 SetDefaultSender 设置的默认发送器。

func (*Plugin) SetDefaultSender

func (p *Plugin) SetDefaultSender(s platform.Sender)

SetDefaultSender sets the default platform-agnostic sender (recommended).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL