Documentation
¶
Overview ¶
Package deadletter 提供针对 platform.Event 的死信条目序列化与落盘/推送实现。
本包位于 platform 层,因此可以合法引用 platform.Event;泛型队列本体位于 infra/dlq,不感知任何平台类型。
与 dlq.Queue 的配合方式(泛型队列以 platform.Event 为元素类型):
q := dlq.New(dlq.Config[platform.Event]{MaxSize: 1000, Workers: 2})
q.AddConsumer(deadletter.PlatformFileConsumer{Path: "/var/log/dlq.jsonl"})
q.Start()
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
type Error struct {
Message string `json:"message"`
Source string `json:"source,omitempty"`
Attempt int `json:"attempt,omitempty"`
}
Error 是用于死信序列化的简化错误表示。
type PlatformDeadLetterEvent ¶
type PlatformDeadLetterEvent struct {
Platform string `json:"platform"`
Kind string `json:"kind"`
RawType string `json:"raw_type"`
ChatID string `json:"chat_id,omitempty"`
SenderID string `json:"sender_id,omitempty"`
TimestampUnix int64 `json:"timestamp_unix,omitempty"`
}
PlatformDeadLetterEvent 记录来自 platform.Event 的可识别字段。
type PlatformDeadLetterRecord ¶
type PlatformDeadLetterRecord struct {
Event *PlatformDeadLetterEvent `json:"event"`
Error Error `json:"error"`
}
PlatformDeadLetterRecord 是平台无关死信条目的 JSON 表示。
type PlatformFileConsumer ¶
type PlatformFileConsumer struct {
Path string
}
PlatformFileConsumer 将 dlq.Item[platform.Event] 以 JSON Lines 格式追加写入文件。
实现 dlq.Consumer[platform.Event],配合 dlq.Queue[platform.Event] 使用。
type PlatformWebhookConsumer ¶
PlatformWebhookConsumer 通过 HTTP POST 将 dlq.Item[platform.Event] 发送至 Webhook。
实现 dlq.Consumer[platform.Event],配合 dlq.Queue[platform.Event] 使用。
MaxRetries 语义:
- < 0:使用默认重试次数 3
- == 0:不重试(仅 1 次尝试)
- > 0:最多重试 MaxRetries 次(共 1 + MaxRetries 次)
Click to show internal directories.
Click to hide internal directories.