bnsq

package
v0.0.0-...-fb49ba0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package bnsq provides a type-safe NSQ pubsub client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelUpdatesNotification

type ChannelUpdatesNotification struct {
	BotName string `json:"bot_name"`
}

ChannelUpdatesNotification is a notification that the IRC service should update its channel list and potentially join/part any changed channels.

type Incoming

type Incoming struct {
	Origin  string       `json:"origin"`
	Message *irc.Message `json:"message"`
}

Incoming is an incoming IRC message as sent over NSQ>

type IncomingPublisher

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

IncomingPublisher publishes incoming messages to NSQ.

func NewIncomingPublisher

func NewIncomingPublisher(addr string, opts ...PublisherOption) *IncomingPublisher

NewIncomingPublisher creates a new IncomingPublisher that will connect to the specified address.

func (*IncomingPublisher) Publish

func (p *IncomingPublisher) Publish(ctx context.Context, origin string, m *irc.Message) error

Publish publishes an incoming message, returning when the message has finished publishing or the context is canceled.

func (*IncomingPublisher) Run

func (p *IncomingPublisher) Run(ctx context.Context) error

Run runs the publisher until the context is canceled.

type IncomingSubscriber

type IncomingSubscriber struct {
	Addr       string
	Channel    string
	Opts       []SubscriberOption
	OnIncoming func(i *Incoming, metadata *Metadata) error
}

IncomingSubscriber subscribes to incoming messages, executing OnIncoming for each message.

func (*IncomingSubscriber) Run

Run runs the subscriber until the context is canceled.

type Metadata

type Metadata struct {
	Timestamp   time.Time `json:"timestamp"`
	TraceSpan   []byte    `json:"trace_span"`
	Correlation xid.ID    `json:"xid"`
}

Metadata contains metadata that will be sent with every NSQ message.

func (*Metadata) ParentSpan

func (m *Metadata) ParentSpan() trace.SpanContext

ParentSpan returns the span that sent the message.

func (*Metadata) With

func (m *Metadata) With(ctx context.Context) context.Context

With adds metadata to the context.

type NotifyPublisher

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

NotifyPublisher publishes notifications to NSQ.

func NewNotifyPublisher

func NewNotifyPublisher(addr string, opts ...PublisherOption) *NotifyPublisher

NewNotifyPublisher creates a new NotifyPublisher that will connect to the specified address.

func (*NotifyPublisher) NotifyChannelUpdates

func (p *NotifyPublisher) NotifyChannelUpdates(ctx context.Context, botName string) error

NotifyChannelUpdates publishes a channel update notification, returning when the notification has finished publishing or the context is canceled.

func (*NotifyPublisher) Run

func (p *NotifyPublisher) Run(ctx context.Context) error

Run runs the publisher until the context is canceled.

type NotifySubscriber

type NotifySubscriber struct {
	Addr                   string
	BotName                string
	Channel                string
	Opts                   []SubscriberOption
	OnNotifyChannelUpdates func(n *ChannelUpdatesNotification, metadata *Metadata) error
}

NotifySubscriber subscribes to notifications, executing a callback for each incoming notification.

func (*NotifySubscriber) Run

func (s *NotifySubscriber) Run(ctx context.Context) error

Run runs the subscriber until the context is canceled.

type Option

type Option interface {
	PublisherOption
	SubscriberOption
}

Option is an option for both a publisher and a subscriber.

func WithClock

func WithClock(clk clock.Clock) Option

WithClock sets the clock used internally. If not set or nil, a real clock is used.

func WithConfig

func WithConfig(config *nsq.Config) Option

WithConfig sets the NSQ config used for a NSQ connection. If not set or nil, the default NSQ configuration will be nil.

type PublisherOption

type PublisherOption interface {
	// contains filtered or unexported methods
}

PublisherOption is an option for a publisher.

type SendMessage

type SendMessage struct {
	Origin  string `json:"origin"`
	Target  string `json:"target"`
	Message string `json:"message"`
}

SendMessage is an outgoing message as sent over NSQ.

type SendMessagePublisher

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

SendMessagePublisher publishes outgoing messages to NSQ.

func NewSendMessagePublisher

func NewSendMessagePublisher(addr string, opts ...PublisherOption) *SendMessagePublisher

NewSendMessagePublisher creates a new SendMessagePublisher that will connect to the specified address.

func (*SendMessagePublisher) Run

Run runs the publisher until the context is canceled.

func (*SendMessagePublisher) SendMessage

func (p *SendMessagePublisher) SendMessage(ctx context.Context, origin, target, message string) error

SendMessage publishes a outgoing message, returning when the message has finished publishing or the context is canceled.

type SendMessageSubscriber

type SendMessageSubscriber struct {
	Addr          string
	Origin        string
	Channel       string
	Opts          []SubscriberOption
	OnSendMessage func(sm *SendMessage, metadata *Metadata) error
}

SendMessageSubscriber subscribes to outgoing message, executing OnSendMessage for each.

func (*SendMessageSubscriber) Run

Run runs the subscriber until the context is canceled.

type SubscriberOption

type SubscriberOption interface {
	// contains filtered or unexported methods
}

SubscriberOption is an option for a subscriber.

func WithMaxAge

func WithMaxAge(d time.Duration) SubscriberOption

WithMaxAge sets the maximum age that a subscriber will accept. If a message is too old, it will be dropped.

Directories

Path Synopsis
Package bnsqmeta propagates NSQ metadata via contexts.
Package bnsqmeta propagates NSQ metadata via contexts.

Jump to

Keyboard shortcuts

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