Added performant in-process message broker to data's routing subpackage
This commit is contained in:
25
pkg/data/routing/interfaces.go
Normal file
25
pkg/data/routing/interfaces.go
Normal file
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user