bnsq

package
v0.0.0-...-3ad7970 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package bnsq provides a type-safe NSQ pubsub client.

Index

Constants

View Source
const (
	EventsubNotifyTopic = "eventsub.notify"
)
View Source
const (
	IncomingWebsocketMessageTopic = "eventsub.incoming"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EventsubNotify

type EventsubNotify struct{}

EventsubNotify is an EventsubNotify message as sent over NSQ.

type EventsubNotifyPublisher

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

EventsubNotifyPublisher publishes EventsubNotify messages to NSQ.

func NewEventsubNotifyPublisher

func NewEventsubNotifyPublisher(addr string, opts ...PublisherOption) *EventsubNotifyPublisher

NewEventsubNotifyPublisher creates a new EventsubNotifyPublisher that will connect to the specified address.

func (*EventsubNotifyPublisher) NotifyEventsubUpdates

func (p *EventsubNotifyPublisher) NotifyEventsubUpdates(ctx context.Context) error

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

func (*EventsubNotifyPublisher) Run

Run runs the publisher until the context is canceled.

type EventsubNotifySubscriber

type EventsubNotifySubscriber struct {
	Addr             string
	Channel          string
	Opts             []SubscriberOption
	OnEventsubNotify func(i *EventsubNotify, metadata *Metadata) error
}

EventsubNotifySubscriber subscribes to EventsubNotify messages, executing OnEventsubNotify for each message.

func (*EventsubNotifySubscriber) Run

Run runs the subscriber until the context is canceled.

type IncomingWebsocketMessage

type IncomingWebsocketMessage struct {
	Message *eventsub.WebsocketMessage `json:"message"`
}

IncomingWebsocketMessage is an IncomingWebsocketMessage message as sent over NSQ.

type IncomingWebsocketMessagePublisher

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

IncomingWebsocketMessagePublisher publishes IncomingWebsocketMessage messages to NSQ.

func NewIncomingWebsocketMessagePublisher

func NewIncomingWebsocketMessagePublisher(addr string, opts ...PublisherOption) *IncomingWebsocketMessagePublisher

NewIncomingWebsocketMessagePublisher creates a new IncomingWebsocketMessagePublisher that will connect to the specified address.

func (*IncomingWebsocketMessagePublisher) Publish

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

func (*IncomingWebsocketMessagePublisher) Run

Run runs the publisher until the context is canceled.

type IncomingWebsocketMessageSubscriber

type IncomingWebsocketMessageSubscriber struct {
	Addr                       string
	Channel                    string
	Opts                       []SubscriberOption
	OnIncomingWebsocketMessage func(i *IncomingWebsocketMessage, metadata *Metadata) error
}

IncomingWebsocketMessageSubscriber subscribes to IncomingWebsocketMessage messages, executing OnIncomingWebsocketMessage for each message.

func (*IncomingWebsocketMessageSubscriber) 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 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 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