deadletter

package
v1.71.1 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 10 Imported by: 0

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

func MarshalPlatformEventItem

func MarshalPlatformEventItem(item dlq.Item[platform.Event]) ([]byte, error)

MarshalPlatformEventItem 序列化平台无关的死信队列条目。

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] 使用。

func (PlatformFileConsumer) Consume

func (f PlatformFileConsumer) Consume(item dlq.Item[platform.Event])

Consume 序列化 dlq.Item[platform.Event] 并追加写入文件。

type PlatformWebhookConsumer

type PlatformWebhookConsumer struct {
	URL        string
	Timeout    time.Duration
	MaxRetries int
}

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 次)

func (PlatformWebhookConsumer) Consume

func (w PlatformWebhookConsumer) Consume(item dlq.Item[platform.Event])

Consume 序列化 dlq.Item[platform.Event] 并通过 HTTP POST 发送至 Webhook。

Jump to

Keyboard shortcuts

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