nsq

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEventBus

func NewEventBus(nsqdAddr string, lookupdAddrs []string, cfg *nsq.Config) (messaging.EventBus, error)

NewEventBus 创建 NSQ 事件总线 nsqdAddr: NSQd 地址(用于发布) lookupdAddrs: NSQLookupd 地址列表(用于订阅) cfg: NSQ 配置,如果为 nil 则使用默认配置

func NewEventBusFromConfig

func NewEventBusFromConfig(config *messaging.Config) (messaging.EventBus, error)

NewEventBusFromConfig 从配置创建事件总线

func NewPublisher

func NewPublisher(addr string, cfg *nsq.Config) (messaging.Publisher, error)

NewPublisher 创建 NSQ 发布者 addr: NSQd 地址,格式为 "host:port" cfg: NSQ 配置

func NewSubscriber

func NewSubscriber(lookupdAddrs []string, cfg *nsq.Config) (messaging.Subscriber, error)

NewSubscriber 创建 NSQ 订阅者 lookupdAddrs: NSQLookupd 地址列表 cfg: NSQ 配置

Types

type TopicCreator

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

TopicCreator NSQ Topic 创建器 用于在 consumer 启动前预先创建 topic,避免 TOPIC_NOT_FOUND 错误日志

func NewTopicCreator

func NewTopicCreator(nsqdAddr string, logger *slog.Logger) *TopicCreator

NewTopicCreator 创建 Topic 创建器 nsqdAddr: NSQd 的 HTTP 地址(注意是 HTTP 端口,通常是 4151,不是 TCP 4150)

func (*TopicCreator) CreateChannel

func (t *TopicCreator) CreateChannel(topic, channel string) error

CreateChannel 创建 channel(可选,channel 会在订阅时自动创建)

func (*TopicCreator) CreateTopic

func (t *TopicCreator) CreateTopic(topic string) error

CreateTopic 创建单个 topic

func (*TopicCreator) CreateTopics

func (t *TopicCreator) CreateTopics(topics []string) (int, []error)

CreateTopics 批量创建 topics 返回成功创建的 topic 数量和遇到的错误

func (*TopicCreator) EnsureTopics

func (t *TopicCreator) EnsureTopics(topics []string) error

EnsureTopics 确保所有 topics 存在 这是一个更友好的接口,会记录日志但不会因单个失败而中断

Jump to

Keyboard shortcuts

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