Movatterモバイル変換


[0]ホーム

URL:


pubsub

package
v2.23.1Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License:AGPL-3.0Imports:20Imported by:0

Details

Repository

github.com/coder/coder

Links

Documentation

Index

Constants

View Source
const BufferSize = 2048

BufferSize is the maximum number of unhandled messages we will bufferfor a subscriber before dropping messages.

View Source
const (EventPubsubWatchdog = "pubsub_watchdog")
View Source
const LatencyMeasureTimeout =time.Second * 10

LatencyMeasureTimeout defines how often to trigger a new background latency measurement.

View Source
const LatencyMessageLength = 36

LatencyMessageLength is the length of a UUIDv4 encoded to hex.

Variables

View Source
var ErrDroppedMessages =xerrors.New("dropped messages")

ErrDroppedMessages is sent to ListenerWithErr if messages are dropped ormight have been dropped.

Functions

This section is empty.

Types

typeLatencyMeasureradded inv2.12.0

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

LatencyMeasurer is used to measure the send & receive latencies of the underlying Pubsub implementation. We use thesemeasurements to export metrics which can indicate when a Pubsub implementation's queue is overloaded and/or full.

funcNewLatencyMeasureradded inv2.12.0

func NewLatencyMeasurer(loggerslog.Logger) *LatencyMeasurer

func (*LatencyMeasurer)Measureadded inv2.12.0

func (lm *LatencyMeasurer) Measure(ctxcontext.Context, pPubsub) (send, recvtime.Duration, errerror)

Measure takes a given Pubsub implementation, publishes a message & immediately receives it, and returns the observed latency.

typeListener

type Listener func(ctxcontext.Context, message []byte)

Listener represents a pubsub handler.

typeListenerWithErr

type ListenerWithErr func(ctxcontext.Context, message []byte, errerror)

ListenerWithErr represents a pubsub handler that can also receive errorindications

typeMemoryPubsub

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

MemoryPubsub is an in-memory Pubsub implementation. It's an exported type so that our test code can do typechecks.

func (*MemoryPubsub)Close

func (*MemoryPubsub) Close()error

func (*MemoryPubsub)Publish

func (m *MemoryPubsub) Publish(eventstring, message []byte)error

func (*MemoryPubsub)Subscribe

func (m *MemoryPubsub) Subscribe(eventstring, listenerListener) (cancel func(), errerror)

func (*MemoryPubsub)SubscribeWithErr

func (m *MemoryPubsub) SubscribeWithErr(eventstring, listenerListenerWithErr) (cancel func(), errerror)

typePGPubsubadded inv2.8.0

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

PGPubsub is a pubsub implementation using PostgreSQL.

funcNew

func New(startCtxcontext.Context, loggerslog.Logger, db *sql.DB, connectURLstring) (*PGPubsub,error)

New creates a new Pubsub implementation using a PostgreSQL connection.

func (*PGPubsub)Closeadded inv2.8.0

func (p *PGPubsub) Close()error

Close closes the pubsub instance.

func (*PGPubsub)Collectadded inv2.8.0

func (p *PGPubsub) Collect(metrics chan<-prometheus.Metric)

Collect implements, along with Describe, the prometheus.Collector interfacefor metrics

func (*PGPubsub)Describeadded inv2.8.0

func (p *PGPubsub) Describe(descs chan<- *prometheus.Desc)

Describe implements, along with Collect, the prometheus.Collector interfacefor metrics.

func (*PGPubsub)Publishadded inv2.8.0

func (p *PGPubsub) Publish(eventstring, message []byte)error

func (*PGPubsub)Subscribeadded inv2.8.0

func (p *PGPubsub) Subscribe(eventstring, listenerListener) (cancel func(), errerror)

Subscribe calls the listener when an event matching the name is received.

func (*PGPubsub)SubscribeWithErradded inv2.8.0

func (p *PGPubsub) SubscribeWithErr(eventstring, listenerListenerWithErr) (cancel func(), errerror)

typePubsub

type Pubsub interface {Subscribe(eventstring, listenerListener) (cancel func(), errerror)SubscribeWithErr(eventstring, listenerListenerWithErr) (cancel func(), errerror)Publish(eventstring, message []byte)errorClose()error}

Pubsub is a generic interface for broadcasting and receiving messages.Implementors should assume high-availability with the backing implementation.

funcNewInMemory

func NewInMemory()Pubsub

typeWatchdogadded inv2.8.0

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

funcNewWatchdogadded inv2.8.0

func NewWatchdog(ctxcontext.Context, loggerslog.Logger, psPubsub) *Watchdog

funcNewWatchdogWithClockadded inv2.8.0

func NewWatchdogWithClock(ctxcontext.Context, loggerslog.Logger, psPubsub, cquartz.Clock) *Watchdog

NewWatchdogWithClock returns a watchdog with the given clock. Product code should always call NewWatchDog.

func (*Watchdog)Closeadded inv2.8.0

func (w *Watchdog) Close()error

func (*Watchdog)Timeoutadded inv2.8.0

func (w *Watchdog) Timeout() <-chan struct{}

Timeout returns a channel that is closed if the watchdog times out. Note that the Timeout() chanwill NOT be closed if the Watchdog is Close'd or its context expires, so it is important to readfrom the Timeout() chan in a select e.g.

w := NewWatchDog(ctx, logger, ps)select {case <-ctx.Done():case <-w.Timeout():

   FreakOut()}

Source Files

View all Source files

Directories

PathSynopsis
package psmock contains a mocked implementation of the pubsub.Pubsub interface for use in tests
package psmock contains a mocked implementation of the pubsub.Pubsub interface for use in tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp