pubsub
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Index¶
- Constants
- Variables
- type LatencyMeasurer
- type Listener
- type ListenerWithErr
- type MemoryPubsub
- type PGPubsub
- func (p *PGPubsub) Close() error
- func (p *PGPubsub) Collect(metrics chan<- prometheus.Metric)
- func (p *PGPubsub) Describe(descs chan<- *prometheus.Desc)
- func (p *PGPubsub) Publish(event string, message []byte) error
- func (p *PGPubsub) Subscribe(event string, listener Listener) (cancel func(), err error)
- func (p *PGPubsub) SubscribeWithErr(event string, listener ListenerWithErr) (cancel func(), err error)
- type Pubsub
- type Watchdog
Constants¶
const BufferSize = 2048
BufferSize is the maximum number of unhandled messages we will bufferfor a subscriber before dropping messages.
const (EventPubsubWatchdog = "pubsub_watchdog")
const LatencyMeasureTimeout =time.Second * 10
LatencyMeasureTimeout defines how often to trigger a new background latency measurement.
const LatencyMessageLength = 36
LatencyMessageLength is the length of a UUIDv4 encoded to hex.
Variables¶
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¶
typeLatencyMeasurer¶added 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.
funcNewLatencyMeasurer¶added inv2.12.0
func NewLatencyMeasurer(loggerslog.Logger) *LatencyMeasurer
typeListenerWithErr¶
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)Subscribe¶
func (m *MemoryPubsub) Subscribe(eventstring, listenerListener) (cancel func(), errerror)
func (*MemoryPubsub)SubscribeWithErr¶
func (m *MemoryPubsub) SubscribeWithErr(eventstring, listenerListenerWithErr) (cancel func(), errerror)
typePGPubsub¶added 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)Collect¶added inv2.8.0
func (p *PGPubsub) Collect(metrics chan<-prometheus.Metric)
Collect implements, along with Describe, the prometheus.Collector interfacefor metrics
func (*PGPubsub)Describe¶added inv2.8.0
func (p *PGPubsub) Describe(descs chan<- *prometheus.Desc)
Describe implements, along with Collect, the prometheus.Collector interfacefor metrics.
func (*PGPubsub)Subscribe¶added inv2.8.0
Subscribe calls the listener when an event matching the name is received.
func (*PGPubsub)SubscribeWithErr¶added 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
typeWatchdog¶added inv2.8.0
type Watchdog struct {// contains filtered or unexported fields}
funcNewWatchdog¶added inv2.8.0
funcNewWatchdogWithClock¶added inv2.8.0
NewWatchdogWithClock returns a watchdog with the given clock. Product code should always call NewWatchDog.
func (*Watchdog)Timeout¶added 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()}