Documentation
¶
Index ¶
- Constants
- Variables
- func GetBuildInfo() (string, string, string)
- func GetEventJetstreamSubjectName(boundary string, position *Position) string
- func GetEventNatsMessageId(preparePosition int64, commitPosition int64) string
- func GetEventsNatsJetstreamStreamStreamName(boundary string) string
- func GetEventsStreamSubjectFilterForSubscription(boundary string, stream *string) string
- func GetEventsSubjectName(boundary string) string
- func GetVersion() string
- func ValidateBoundaryName(name string) error
- type Backoff
- type Boundarydeprecated
- type BoundaryDefinitiondeprecated
- type BoundaryIndex
- type BoundaryIndexCondition
- type BoundaryIndexField
- type BoundaryIndexManager
- type BoundaryPlacementdeprecated
- type BoundaryStatusdeprecated
- type ComparationResult
- type ConditionCombinator
- type CreateIndexRequest
- type Criterion
- type CustomEventStream
- type Direction
- type DropIndexRequest
- type Event
- type EventPollingManager
- type EventPublishingTracker
- type EventSignal
- type EventStore
- func (s *EventStore) ActivateBoundary(boundary string) error
- func (s *EventStore) CreateIndex(ctx context.Context, req *CreateIndexRequest) error
- func (s *EventStore) DropIndex(ctx context.Context, req *DropIndexRequest) error
- func (s *EventStore) EnableBoundaryActivationGate(initiallyActive ...string) error
- func (s *EventStore) EnableOpenTelemetryMetrics() error
- func (s *EventStore) EnsureBoundary(ctx context.Context, boundary string) error
- func (s *EventStore) GetEvents(ctx context.Context, req *GetEventsRequest) (*GetEventsResponse, error)
- func (s *EventStore) GetIndex(ctx context.Context, req *GetIndexRequest) (*GetIndexResponse, error)
- func (s *EventStore) GetLatestByCriteria(ctx context.Context, req *GetLatestByCriteriaRequest) (*GetLatestByCriteriaResponse, error)
- func (s *EventStore) ListIndexes(ctx context.Context, req *ListIndexesRequest) (*ListIndexesResponse, error)
- func (s *EventStore) Ping(ctx context.Context) error
- func (s *EventStore) RequireBoundaryActive(boundary string) error
- func (s *EventStore) SaveEvents(ctx context.Context, req *SaveEventsRequest) (resp *WriteResult, err error)
- func (s *EventStore) SubscribeToAllEvents(ctx context.Context, request coreeventstore.SubscribeRequest, ...) error
- type EventStreamConfig
- type EventToSave
- type EventWithMapTags
- type EventsRetriever
- type EventsSaver
- type GetEventsRequest
- type GetEventsResponse
- type GetIndexRequest
- type GetIndexResponse
- type GetLatestByCriteriaRequest
- type GetLatestByCriteriaResponse
- type IndexCondition
- type IndexField
- type JetStreamLockProvider
- type LatestByCriteriaBatch
- type LatestByCriteriaQuery
- type LatestCriterionMatch
- type LatestCriterionResult
- type ListIndexesRequest
- type ListIndexesResponse
- type LockLease
- type LockLeaseProvider
- type LockProvider
- type MessageHandler
- type OrisunServer
- func (c *OrisunServer) ActivateBoundary(_ context.Context, boundary string) error
- func (c *OrisunServer) EnableBoundaryActivationGate(initiallyActive ...string) error
- func (c *OrisunServer) EnsureBoundary(ctx context.Context, boundary string) error
- func (c *OrisunServer) GetEvents(ctx context.Context, req *GetEventsRequest) (ReadEventBatch, error)
- func (c *OrisunServer) GetLatestByCriteria(ctx context.Context, query LatestByCriteriaQuery) (LatestByCriteriaBatch, error)
- func (c *OrisunServer) RequireBoundaryActive(boundary string) error
- func (c *OrisunServer) SaveEvents(ctx context.Context, events []EventWithMapTags, boundary string, ...) (*Position, error)
- func (c *OrisunServer) SubscribeToEvents(ctx context.Context, request coreeventstore.SubscribeRequest, ...) error
- type PollingSignal
- type Position
- type PreparedEvent
- type PreparedEventBatch
- type Query
- type ReadCriterion
- type ReadEvent
- type ReadEventBatch
- type ReadTag
- type Role
- type SaveEventsRequest
- type SaveQuery
- type Tag
- type User
- type UserContextKeyType
- type ValueType
- type WriteResult
Constants ¶
const ( // Deprecated: use boundary.StatusProvisioning. BoundaryStatusProvisioning = boundarymodel.StatusProvisioning // Deprecated: use boundary.StatusActive. BoundaryStatusActive = boundarymodel.StatusActive // Deprecated: use boundary.StatusFailed. BoundaryStatusFailed = boundarymodel.StatusFailed )
const ( IndexCombinatorAND = "AND" IndexCombinatorOR = "OR" BoundaryIndexStateBuilding = "building" BoundaryIndexStateReady = "ready" )
const ( // DefaultReadBatchSize is used by storage backends when an in-process // caller does not provide a page size. DefaultReadBatchSize uint32 = 1_000 // MaxReadBatchSize bounds one database read and its result allocation. // Larger logical reads must advance by position and fetch another page. MaxReadBatchSize uint32 = 10_000 )
const (
EventsSubjectName = "events"
)
const (
StreamDoesNotExist = -1
)
Variables ¶
var BuildTime = "unknown"
BuildTime is the time when the binary was built. This will be overridden during build by the -ldflags="-X 'orisun/orisun.BuildTime=<timestamp>'" flag.
var ErrQueueFull = errors.New("message handler queue full")
var GitCommit = "unknown"
GitCommit is the git commit hash from which the binary was built. This will be overridden during build by the -ldflags="-X 'orisun/orisun.GitCommit=<hash>'" flag.
var Roles = []Role{RoleAdmin, RoleOperations}
var Version = "dev"
Version is the current version of Orisun. This will be overridden during build by the -ldflags="-X 'orisun/orisun.Version=v1.2.3'" flag.
Functions ¶
func GetBuildInfo ¶
GetBuildInfo returns the version, build time, and git commit hash.
func GetEventNatsMessageId ¶
func GetEventsSubjectName ¶
func ValidateBoundaryName ¶ added in v0.8.0
ValidateBoundaryName is retained for compatibility. Deprecated: use boundary.ValidateName.
Types ¶
type Backoff ¶
Backoff implements capped exponential backoff with jitter. Use for retry loops to avoid thundering-herd on shared resources (PG advisory locks, etc).
type Boundary
deprecated
added in
v0.8.0
type Boundary = boundarymodel.Boundary
Deprecated: use boundary.Boundary.
type BoundaryDefinition
deprecated
added in
v0.8.0
type BoundaryDefinition = boundarymodel.Definition
Deprecated: use boundary.Definition.
type BoundaryIndex ¶ added in v0.9.3
type BoundaryIndex struct {
Name string
Fields []BoundaryIndexField
Conditions []BoundaryIndexCondition
Combinator string
State string
}
type BoundaryIndexCondition ¶
type BoundaryIndexField ¶
type BoundaryIndexManager ¶
type BoundaryIndexManager interface {
CreateBoundaryIndex(ctx context.Context, boundary, name string, fields []BoundaryIndexField, conditions []BoundaryIndexCondition, combinator string) error
DropBoundaryIndex(ctx context.Context, boundary, name string) error
ListBoundaryIndexes(ctx context.Context, boundary string) ([]BoundaryIndex, error)
GetBoundaryIndex(ctx context.Context, boundary, name string) (*BoundaryIndex, error)
}
type BoundaryPlacement
deprecated
added in
v0.8.0
type BoundaryPlacement = boundarymodel.Placement
Deprecated: use boundary.Placement.
type BoundaryStatus
deprecated
added in
v0.8.0
type BoundaryStatus = boundarymodel.Status
Deprecated: use boundary.Status.
type ComparationResult ¶
type ComparationResult int
const IsEqual ComparationResult = 0
const IsGreaterThan ComparationResult = 1
const IsLessThan ComparationResult = -1
func ComparePositions ¶
func ComparePositions(p1, p2 *Position) ComparationResult
type ConditionCombinator ¶
type ConditionCombinator int32
const ( ConditionCombinator_AND ConditionCombinator = iota ConditionCombinator_OR )
type CreateIndexRequest ¶
type CreateIndexRequest struct {
Boundary string
Name string
Fields []*IndexField
Conditions []*IndexCondition
ConditionCombinator ConditionCombinator
}
type CustomEventStream ¶
type CustomEventStream struct {
// contains filtered or unexported fields
}
func NewCustomEventStream ¶
func NewCustomEventStream(ctx context.Context) *CustomEventStream
func (*CustomEventStream) Context ¶
func (s *CustomEventStream) Context() context.Context
func (*CustomEventStream) Events ¶
func (s *CustomEventStream) Events() <-chan *Event
Events returns the channel for consuming events
func (*CustomEventStream) Recv ¶
func (s *CustomEventStream) Recv() (*Event, error)
func (*CustomEventStream) Send ¶
func (s *CustomEventStream) Send(event *Event) error
type DropIndexRequest ¶
type Event ¶
type Event struct {
EventId string `json:"event_id"`
EventType string `json:"event_type"`
Data string `json:"data"`
Metadata string `json:"metadata"`
Position *Position `json:"position"`
DateCreated time.Time `json:"date_created"`
}
Event is the transport-neutral event shape used by legacy in-process command handlers. Storage backends use ReadEvent directly.
type EventPollingManager ¶ added in v0.8.0
type EventPollingManager struct {
// contains filtered or unexported fields
}
func StartEventPolling ¶
func StartEventPolling( ctx context.Context, config c.AppConfig, lockProvider LockProvider, getEvents EventsRetriever, js jetstream.JetStream, eventPublishingTracker EventPublishingTracker, signalProvider func(string) EventSignal, logger logging.Logger) *EventPollingManager
func (*EventPollingManager) StartBoundary ¶ added in v0.8.0
func (m *EventPollingManager) StartBoundary(boundary string) error
StartBoundary starts exactly one publishing loop for a boundary in this process. Cluster-wide exclusivity remains enforced by the lock lease.
type EventPublishingTracker ¶
type EventPublishingTracker interface {
GetLastPublishedEventPosition(ctx context.Context, boundary string) (Position, error)
InsertLastPublishedEvent(ctx context.Context, boundary string, transactionID, globalID int64) error
}
EventPublishingTracker stores per-boundary durable publisher checkpoints.
type EventSignal ¶
EventSignal reports that new events may be available.
type EventStore ¶
type EventStore struct {
// contains filtered or unexported fields
}
func InitializeEventStore ¶
func InitializeEventStore( ctx context.Context, config c.AppConfig, saveEvents EventsSaver, getEvents EventsRetriever, lockProvider LockProvider, indexManager BoundaryIndexManager, js jetstream.JetStream, logger logging.Logger) *EventStore
func NewEventStoreServer ¶
func NewEventStoreServer( js jetstream.JetStream, saveEventsFn EventsSaver, getEventsFn EventsRetriever, lockProvider LockProvider, indexManager BoundaryIndexManager, streamCfg EventStreamConfig, logger logging.Logger, ) *EventStore
func (*EventStore) ActivateBoundary ¶ added in v0.8.0
func (s *EventStore) ActivateBoundary(boundary string) error
ActivateBoundary exposes a boundary to public requests after its activation event is durable. It is idempotent for replay and clustered delivery.
func (*EventStore) CreateIndex ¶
func (s *EventStore) CreateIndex(ctx context.Context, req *CreateIndexRequest) error
func (*EventStore) DropIndex ¶
func (s *EventStore) DropIndex(ctx context.Context, req *DropIndexRequest) error
func (*EventStore) EnableBoundaryActivationGate ¶ added in v0.8.0
func (s *EventStore) EnableBoundaryActivationGate(initiallyActive ...string) error
EnableBoundaryActivationGate makes public event-store operations require a locally observed ACTIVE catalog state. The bootstrap boundary is supplied as initially active so the catalog can replay itself before application boundaries are exposed.
func (*EventStore) EnableOpenTelemetryMetrics ¶ added in v0.9.3
func (s *EventStore) EnableOpenTelemetryMetrics() error
EnableOpenTelemetryMetrics attaches event-store instruments to the current global OpenTelemetry MeterProvider. Metrics are disabled until this is called.
func (*EventStore) EnsureBoundary ¶ added in v0.8.0
func (s *EventStore) EnsureBoundary(ctx context.Context, boundary string) error
EnsureBoundary creates or updates the real-time stream for a boundary. It is idempotent so provisioning retries can safely call it after the durable backend has already been created.
func (*EventStore) GetEvents ¶
func (s *EventStore) GetEvents(ctx context.Context, req *GetEventsRequest) (*GetEventsResponse, error)
func (*EventStore) GetIndex ¶ added in v0.9.3
func (s *EventStore) GetIndex(ctx context.Context, req *GetIndexRequest) (*GetIndexResponse, error)
func (*EventStore) GetLatestByCriteria ¶
func (s *EventStore) GetLatestByCriteria(ctx context.Context, req *GetLatestByCriteriaRequest) (*GetLatestByCriteriaResponse, error)
func (*EventStore) ListIndexes ¶ added in v0.9.3
func (s *EventStore) ListIndexes(ctx context.Context, req *ListIndexesRequest) (*ListIndexesResponse, error)
func (*EventStore) RequireBoundaryActive ¶ added in v0.8.0
func (s *EventStore) RequireBoundaryActive(boundary string) error
RequireBoundaryActive rejects unknown, provisioning, and failed catalog boundaries before a public request reaches a backend.
func (*EventStore) SaveEvents ¶
func (s *EventStore) SaveEvents(ctx context.Context, req *SaveEventsRequest) (resp *WriteResult, err error)
func (*EventStore) SubscribeToAllEvents ¶
func (s *EventStore) SubscribeToAllEvents( ctx context.Context, request coreeventstore.SubscribeRequest, handler coreeventstore.EventHandler, ) error
type EventStreamConfig ¶
type EventToSave ¶
type EventWithMapTags ¶
type EventWithMapTags struct {
EventId string `json:"event_id"`
EventType string `json:"event_type"`
Data any `json:"data"`
Metadata any `json:"metadata"`
}
EventWithMapTags is the flexible input representation used by embedding APIs.
type EventsRetriever ¶
type EventsRetriever interface {
GetBatch(ctx context.Context, req *GetEventsRequest) (ReadEventBatch, error)
GetLatestByCriteria(ctx context.Context, query LatestByCriteriaQuery) (LatestByCriteriaBatch, error)
}
EventsRetriever reads backend-neutral event batches and carried-state snapshots without depending on a network transport.
type EventsSaver ¶
type EventsSaver interface {
SavePrepared(
ctx context.Context,
events PreparedEventBatch,
boundary string,
expectedPosition *Position,
subSet *Query,
) (transactionID string, globalID int64, err error)
}
EventsSaver accepts canonical batches prepared at an API boundary.
type GetEventsRequest ¶
type GetEventsResponse ¶
type GetEventsResponse struct {
Events []*Event
}
type GetIndexRequest ¶ added in v0.9.3
type GetIndexResponse ¶ added in v0.9.3
type GetIndexResponse struct {
Index *BoundaryIndex
}
type GetLatestByCriteriaResponse ¶
type GetLatestByCriteriaResponse struct {
Results []*LatestCriterionResult
ContextPosition *Position
}
type IndexCondition ¶
type IndexField ¶
type JetStreamLockProvider ¶
type JetStreamLockProvider struct {
// contains filtered or unexported fields
}
JetStreamLockProvider implements a renewable, revision-fenced distributed lock using NATS JetStream KV.
func NewJetStreamLockProvider ¶
func NewJetStreamLockProvider(ctx context.Context, js jetstream.JetStream, logger logging.Logger) (*JetStreamLockProvider, error)
NewJetStreamLockProvider creates a new JetStreamLockProvider.
func (*JetStreamLockProvider) AcquireLock ¶ added in v0.7.0
func (p *JetStreamLockProvider) AcquireLock(ctx context.Context, lockName string) (LockLease, error)
AcquireLock acquires a renewable, token-fenced lease. An expired lease may be replaced with a revision-guarded update.
type LatestByCriteriaBatch ¶
type LatestByCriteriaBatch struct {
Matches []LatestCriterionMatch
ContextCommitPosition int64
ContextPreparePosition int64
}
LatestByCriteriaBatch is the packed result used by embedded callers and storage backends. Matches is positionally aligned with the input criteria.
type LatestByCriteriaQuery ¶
type LatestByCriteriaQuery struct {
Boundary string
Criteria []ReadCriterion
}
LatestByCriteriaQuery is the protobuf-free request used below the gRPC boundary.
type LatestCriterionMatch ¶
LatestCriterionMatch is positionally aligned with the corresponding input criterion. Event is valid only when Found is true.
type LatestCriterionResult ¶
type ListIndexesRequest ¶ added in v0.9.3
type ListIndexesRequest struct {
Boundary string
}
type ListIndexesResponse ¶ added in v0.9.3
type ListIndexesResponse struct {
Indexes []*BoundaryIndex
}
type LockLeaseProvider ¶
type LockLeaseProvider interface {
AcquireLock(ctx context.Context, lockName string) (LockLease, error)
}
LockLeaseProvider exposes explicit lock lifecycles to embedded subscribers and server-side publishers.
type LockProvider ¶
LockProvider coordinates named work within a backend runtime.
type MessageHandler ¶
type MessageHandler[T any] struct { // contains filtered or unexported fields }
func NewMessageHandler ¶
func NewMessageHandler[T any](ctx context.Context) *MessageHandler[T]
NewMessageHandler Add constructor and methods for the generic stream
func NewMessageHandlerWithBuffer ¶
func NewMessageHandlerWithBuffer[T any](ctx context.Context, bufferSize int) *MessageHandler[T]
NewMessageHandlerWithBuffer allows configuring the internal buffer size
func (*MessageHandler[T]) Close ¶
func (s *MessageHandler[T]) Close()
Close marks the handler as closed to prevent further sends
func (*MessageHandler[T]) Context ¶
func (s *MessageHandler[T]) Context() context.Context
func (*MessageHandler[T]) Recv ¶
func (s *MessageHandler[T]) Recv() (*T, error)
func (*MessageHandler[T]) Send ¶
func (s *MessageHandler[T]) Send(event *T) error
func (*MessageHandler[T]) TrySend ¶
func (s *MessageHandler[T]) TrySend(event *T) error
TrySend attempts to enqueue without blocking and returns ErrQueueFull if buffer is full
type OrisunServer ¶
type OrisunServer struct {
// contains filtered or unexported fields
}
OrisunServer provides a high-level interface to interact with the Orisun event store
func NewOrisunServer ¶
func NewOrisunServer( ctx context.Context, saveEvents EventsSaver, getEvents EventsRetriever, lockProvider LockProvider, js jetstream.JetStream, logger logging.Logger, ) (*OrisunServer, error)
NewOrisunServer creates a new Orisun client with the provided configuration
func (*OrisunServer) ActivateBoundary ¶ added in v0.8.0
func (c *OrisunServer) ActivateBoundary(_ context.Context, boundary string) error
ActivateBoundary exposes a durably activated boundary to public operations.
func (*OrisunServer) EnableBoundaryActivationGate ¶ added in v0.8.0
func (c *OrisunServer) EnableBoundaryActivationGate(initiallyActive ...string) error
EnableBoundaryActivationGate makes public operations require an ACTIVE boundary catalog state. The admin boundary is supplied during bootstrap.
func (*OrisunServer) EnsureBoundary ¶ added in v0.8.0
func (c *OrisunServer) EnsureBoundary(ctx context.Context, boundary string) error
EnsureBoundary prepares the real-time stream for a newly provisioned boundary. Durable backend creation remains the backend adapter's concern.
func (*OrisunServer) GetEvents ¶
func (c *OrisunServer) GetEvents(ctx context.Context, req *GetEventsRequest) (ReadEventBatch, error)
GetEvents retrieves events from the event store based on the request.
func (*OrisunServer) GetLatestByCriteria ¶
func (c *OrisunServer) GetLatestByCriteria(ctx context.Context, query LatestByCriteriaQuery) (LatestByCriteriaBatch, error)
GetLatestByCriteria returns the latest event per criterion from one backend read snapshot, plus the max observed position as the optimistic-lock token for the combined context.
func (*OrisunServer) RequireBoundaryActive ¶ added in v0.8.0
func (c *OrisunServer) RequireBoundaryActive(boundary string) error
RequireBoundaryActive validates a boundary against the local catalog gate.
func (*OrisunServer) SaveEvents ¶
func (c *OrisunServer) SaveEvents(ctx context.Context, events []EventWithMapTags, boundary string, expectedPosition *Position, streamSubSet *Query) (*Position, error)
SaveEvents saves a batch of events to the event store
func (*OrisunServer) SubscribeToEvents ¶
func (c *OrisunServer) SubscribeToEvents( ctx context.Context, request coreeventstore.SubscribeRequest, handler coreeventstore.EventHandler, ) error
SubscribeToEvents subscribes to events from a boundary with the given handler
type PollingSignal ¶
type PollingSignal struct {
// contains filtered or unexported fields
}
func NewPollingSignal ¶
func NewPollingSignal(interval time.Duration) *PollingSignal
func (*PollingSignal) Stop ¶
func (s *PollingSignal) Stop()
type Position ¶
type Position struct {
CommitPosition int64 `json:"commit_position"`
PreparePosition int64 `json:"prepare_position"`
}
Position identifies one event in a boundary's total order.
func FirstPosition ¶
func FirstPosition() Position
FirstPosition returns the first persisted event position.
func NotExistsPosition ¶
func NotExistsPosition() Position
NotExistsPosition is the optimistic-concurrency position before any event.
type PreparedEvent ¶
PreparedEvent is the canonical backend-facing event representation.
func (PreparedEvent) MarshalJSON ¶
func (e PreparedEvent) MarshalJSON() ([]byte, error)
MarshalJSON preserves the canonical data and metadata as JSON values.
type PreparedEventBatch ¶
type PreparedEventBatch []PreparedEvent
PreparedEventBatch keeps canonical event descriptors contiguous.
func PrepareEventsForSave ¶
func PrepareEventsForSave(events []EventWithMapTags) (PreparedEventBatch, error)
PrepareEventsForSave normalizes flexible embedding input exactly once.
type ReadCriterion ¶
type ReadCriterion struct {
Tags []ReadTag
}
ReadCriterion is one conjunction of equality tags. Criteria in a LatestByCriteriaQuery are independent and retain their input order.
type ReadEvent ¶
type ReadEvent struct {
EventId string
EventType string
Data string
Metadata string
CommitPosition int64
PreparePosition int64
DateCreated time.Time
}
ReadEvent is the backend-neutral, contiguous read representation. Positions and timestamps are scalar values so storage and internal consumers do not allocate an object graph for every row.
func (*ReadEvent) Event ¶ added in v0.8.0
Event materializes the legacy in-process event representation.
func (ReadEvent) MarshalJSON ¶
MarshalJSON preserves the stable NATS event envelope while keeping the publisher on the packed representation.
type ReadEventBatch ¶
type ReadEventBatch []ReadEvent
ReadEventBatch keeps database results in one value slab.
func (ReadEventBatch) Response ¶ added in v0.8.0
func (b ReadEventBatch) Response() *GetEventsResponse
Response materializes the legacy in-process response shape.
type ReadTag ¶
ReadTag is the protobuf-free criterion tag used by embedded callers and storage backends.
type SaveEventsRequest ¶
type SaveEventsRequest struct {
Boundary string
Query *SaveQuery
Events []*EventToSave
}
type UserContextKeyType ¶
type UserContextKeyType string
const UserContextKey UserContextKeyType = "user"
type WriteResult ¶
type WriteResult struct {
LogPosition *Position
}