pubsub

package
v1.3.2-rc3 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferingEnvelope

type BufferingEnvelope struct {
	Offsets  []int64 `json:"offsets"`
	Payloads []byte  `json:"payloads"`
}

func (*BufferingEnvelope) Size

func (e *BufferingEnvelope) Size() int64

Size return the size of the buffered payloads in the envelope

type BufferingPubSub

type BufferingPubSub[T any] struct {
	// contains filtered or unexported fields
}

BufferingPubSub is a PubSub implementation that buffers messages in memory and flushes them to the delegate PubSub when the buffer is full or the buffer age is reached

func NewBufferingPubSub

func NewBufferingPubSub[T any](params BufferingPubSubParams) *BufferingPubSub[T]

func (*BufferingPubSub[T]) Close

func (p *BufferingPubSub[T]) Close(ctx context.Context) (err error)

func (*BufferingPubSub[T]) Handle

func (p *BufferingPubSub[T]) Handle(ctx context.Context, envelope BufferingEnvelope) error

func (*BufferingPubSub[T]) Publish

func (p *BufferingPubSub[T]) Publish(ctx context.Context, message T) error

func (*BufferingPubSub[T]) Subscribe

func (p *BufferingPubSub[T]) Subscribe(ctx context.Context, subscriber Subscriber[T]) (err error)

type BufferingPubSubParams

type BufferingPubSubParams struct {
	DelegatePubSub PubSub[BufferingEnvelope]
	MaxBufferSize  int64
	MaxBufferAge   time.Duration
}

type ChainedPublisher added in v1.0.4

type ChainedPublisher[T any] struct {
	// contains filtered or unexported fields
}

func NewChainedPublisher added in v1.0.4

func NewChainedPublisher[T any](ignoreErrors bool) *ChainedPublisher[T]

func (*ChainedPublisher[T]) Add added in v1.0.4

func (c *ChainedPublisher[T]) Add(publisher Publisher[T])

Add publisher to the chain

func (*ChainedPublisher[T]) Publish added in v1.0.4

func (c *ChainedPublisher[T]) Publish(ctx context.Context, message T) error

type ChainedSubscriber

type ChainedSubscriber[T any] struct {
	// contains filtered or unexported fields
}

func NewChainedSubscriber

func NewChainedSubscriber[T any](ignoreErrors bool) *ChainedSubscriber[T]

func (*ChainedSubscriber[T]) Add

func (c *ChainedSubscriber[T]) Add(subscriber Subscriber[T])

Add subscriber to the chain

func (*ChainedSubscriber[T]) Handle

func (c *ChainedSubscriber[T]) Handle(ctx context.Context, message T) error

Handle message by calling all subscribers in the chain

type InMemoryPubSub

type InMemoryPubSub[T any] struct {
	// contains filtered or unexported fields
}

InMemoryPubSub is a simple in-memory pubsub implementation used for testing

func NewInMemoryPubSub

func NewInMemoryPubSub[T any]() *InMemoryPubSub[T]

func (*InMemoryPubSub[T]) Close

func (p *InMemoryPubSub[T]) Close(ctx context.Context) error

func (*InMemoryPubSub[T]) Publish

func (p *InMemoryPubSub[T]) Publish(ctx context.Context, message T) error

func (*InMemoryPubSub[T]) Subscribe

func (p *InMemoryPubSub[T]) Subscribe(ctx context.Context, subscriber Subscriber[T]) error

type InMemorySubscriber

type InMemorySubscriber[T any] struct {
	// contains filtered or unexported fields
}

InMemorySubscriber is a simple in-memory subscriber implementation used for testing

func NewInMemorySubscriber

func NewInMemorySubscriber[T any]() *InMemorySubscriber[T]

func (*InMemorySubscriber[T]) Events

func (s *InMemorySubscriber[T]) Events() []T

func (*InMemorySubscriber[T]) Handle

func (s *InMemorySubscriber[T]) Handle(ctx context.Context, message T) error

type LoggingSubscriber added in v1.0.4

type LoggingSubscriber[T any] struct {
	// contains filtered or unexported fields
}

LoggingSubscriber that just logs the message.

func NewLoggingSubscriber added in v1.0.4

func NewLoggingSubscriber[T any](level zerolog.Level) *LoggingSubscriber[T]

func (*LoggingSubscriber[T]) Handle added in v1.0.4

func (c *LoggingSubscriber[T]) Handle(ctx context.Context, message T) error

type NoopSubscriber added in v1.0.4

type NoopSubscriber[T any] struct {
}

NoopSubscriber is a subscriber that does nothing. It is useful for adding subscribers to the pubsub network that only participate in the gossip protocol, but do not actually handle messages. This is useful when the network is small and not enough peers are available to strengthen the network.

func NewNoopSubscriber added in v1.0.4

func NewNoopSubscriber[T any]() *NoopSubscriber[T]

func (*NoopSubscriber[T]) Handle added in v1.0.4

func (c *NoopSubscriber[T]) Handle(ctx context.Context, message T) error

type PubSub

type PubSub[T any] interface {
	// Publish a message
	Publish(ctx context.Context, message T) error
	// Subscribe to messages
	Subscribe(ctx context.Context, subscriber Subscriber[T]) error
	// Close the PubSub and release resources, if any
	Close(ctx context.Context) error
}

PubSub enables publishing messages to subscribers

type Publisher added in v1.0.4

type Publisher[T any] interface {
	Publish(ctx context.Context, message T) error
}

Publisher handles messages publishes to PubSub

type PublisherFunc added in v1.0.4

type PublisherFunc[T any] func(ctx context.Context, message T) error

PublisherFunc is a helper function that implements Publisher interface

func (PublisherFunc[T]) Publish added in v1.0.4

func (f PublisherFunc[T]) Publish(ctx context.Context, message T) error

type Subscriber

type Subscriber[T any] interface {
	Handle(ctx context.Context, message T) error
}

Subscriber handles messages publishes to PubSub

type SubscriberFunc

type SubscriberFunc[T any] func(ctx context.Context, message T) error

SubscriberFunc is a helper function that implements Subscriber interface

func (SubscriberFunc[T]) Handle

func (f SubscriberFunc[T]) Handle(ctx context.Context, message T) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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