26 lines
811 B
Go
26 lines
811 B
Go
package routing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gitlab.michelsen.id/phillmichelsen/tessera/pkg/data"
|
|
)
|
|
|
|
// Publisher is the write-side handle given to data sources.
|
|
type Publisher interface {
|
|
Publish(env data.Envelope)
|
|
}
|
|
|
|
// Subscriber is the read-side handle given to consumers (data sinks).
|
|
type Subscriber interface {
|
|
// Receive blocks until a message is available or the context cancels.
|
|
// Best for general low-latency consumers that shouldn't burn CPU.
|
|
// Typically more than enough for most situations
|
|
Receive(ctx context.Context) (data.Envelope, error)
|
|
|
|
// TryReceive attempts to read one message lock-free.
|
|
// Returns (envelope, true, nil) if successful, or false if nothing is available.
|
|
// Polling TryReceive without a wait will most likely spike the CPU
|
|
TryReceive() (data.Envelope, bool, error)
|
|
}
|