← ClaudeAtlas

pulsar-golisted

Go Pulsar 消息队列专家 - 消息生产消费、订阅模式(Exclusive/Shared/Failover/KeyShared)、死信队列、链路追踪、Schema 管理、延迟消息。适用:多租户消息系统、延迟/定时投递、海量 Topic 场景、跨地域复制、多种订阅模式灵活切换。不适用:团队已深度使用 Kafka 且无迁移计划、仅需简单 Pub/Sub(用 Redis Streams/NATS)、运维资源有限(Pulsar 依赖 BookKeeper+ZooKeeper)。触发词:pulsar, 消息队列, producer, consumer, 订阅, DLQ, 死信, 延迟消息, schema, topic, 多租户
omeyang/Thoth · ★ 0 · AI & Automation · score 73
Install: claude install-skill omeyang/Thoth
# Go Pulsar 专家 使用 Go pulsar-client-go 开发消息队列功能:$ARGUMENTS --- ## 1. 客户端管理 ### 创建客户端 ```go func NewPulsarClient(serviceURL string) (pulsar.Client, error) ``` - 配置:OperationTimeout=30s, ConnectionTimeout=10s, MaxConnectionsPerBroker=5 - 可选认证:`pulsar.NewAuthenticationToken("token")` ### 包装器模式 ```go type Pulsar struct { client pulsar.Client } func New(client pulsar.Client) *Pulsar func (p *Pulsar) Client() pulsar.Client func (p *Pulsar) Close() ``` > 完整实现见 [references/examples.md](references/examples.md#1-客户端管理) --- ## 2. 生产者 ### 创建生产者 ```go func (p *Pulsar) CreateProducer(topic string) (pulsar.Producer, error) ``` - 批量发送:BatchingMaxPublishDelay=10ms, BatchingMaxMessages=1000 - 压缩:LZ4 - 分区路由:按 Key 哈希路由到固定分区 ### 发送消息 | 方法 | 签名 | 说明 | |------|------|------| | 同步 | `Send(ctx, producer, msg) (MessageID, error)` | 等待确认 | | 异步 | `SendAsync(ctx, producer, msg, callback)` | 回调通知 | | 批量 | `SendBatch(ctx, producer, messages) error` | 并发异步+WaitGroup | ### 延迟消息 ```go // 延迟投递 producer.Send(ctx, &pulsar.ProducerMessage{Payload: data, DeliverAfter: 5 * time.Minute}) // 定时投递 producer.Send(ctx, &pulsar.ProducerMessage{Payload: data, DeliverAt: targetTime}) ``` > 完整实现见 [references/examples.md](references/examples.md#2-生产者) --- ## 3. 消费者 ### 订阅模式 | 模式 | 函数 | 特点 | |------|------|------| | Exclusive | `SubscribeExclusive()` | 独占,只有一个消费者 | | Shared | `SubscribeShared()` | 共享,多消费者轮询 | | Failover | `SubscribeFailover()` | 故障转移 | | KeyShared | `SubscribeKeyShared()` | 按 Key 分区,保证同