messaging

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

README

pkg/messaging

Intention

pkg/messaging defines a narrow message-queue abstraction for resource lifecycle events. Its job is to let platform code consume replayable resource messages without coupling directly to a specific backend implementation.

The key semantic is replayable lifecycle delivery. Implementations must be able to replay all currently active resources on startup so consumers can re-witness state after restarts and continue any required work that might otherwise have been missed.

The main proven use case for that replay behavior today is deletion recovery. Deletion in the platform is often reference-driven rather than immediate. A resource such as a project may remain blocked from deletion while other resources still reference it. Messaging consumers are used to fan deletion outward, remove dependents, and allow those references to clear so deletion can complete eventually.

The abstraction is intended to support backends such as Kubernetes today and systems such as Kafka or NATS later. The current envelope is deliberately small: it carries a resource ID and optional deletion timestamp, and consumers are expected to rehydrate any richer state they need from the system of record.

See kubernetes for the current backend and consumer for the current reusable consumer pattern.

Invariants And Guard Rails

  • This package is a resource-lifecycle messaging abstraction, not a general-purpose event bus API.
  • Queue implementations must replay all active resources on startup so consumers can recover missed work after restarts.
  • If a consumer returns an error, the queue implementation must requeue or retry the event rather than treating it as successfully handled.
  • Consumers should be written to tolerate replay and repeated delivery. The contract assumes recovery and retries, not exactly-once processing.
  • The envelope is intentionally minimal. Consumers should derive any richer state they need from the resource ID and the system of record rather than expecting a full event payload here.
  • Deletion is the most important currently proven semantic carried by this abstraction. A nil deletion timestamp routes the message as a live or non-deleting resource event; a populated deletion timestamp means deletion fan-out or other cleanup logic may need to run.

Caveats

  • The abstraction is broader in intent than in its current in-tree implementation. Today there is only one backend, and it is effectively controller-runtime reconciliation wrapped in a queue-shaped interface.
  • The current Kubernetes backend is tightly coupled to controller-runtime manager and reconcile mechanics, so future non-Kubernetes backends are intended but not yet pressure-tested by this abstraction.
  • The envelope is intentionally sparse. That keeps queue semantics simple, but it also limits this abstraction to consumers that can rehydrate needed state from the system of record.
  • The main proven use case today is deletion fan-out and cascading cleanup. If future consumers expect richer event semantics, this package contract may need to grow or split.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Consumer

type Consumer interface {
	// Consume consumes an event from the queue.
	Consume(ctx context.Context, envelope *Envelope) error
}

type Envelope

type Envelope struct {
	// ResourceID the GUID of a resource.
	ResourceID string
	// DeletionTimestamp describes whether the resource is being deleted
	// or not, and is used for routing.  If not set this is a creation or
	// update event.
	DeletionTimestamp *time.Time
}

Envelope is a generic messaging envelope for resource messages.

type Queue

type Queue interface {
	// Run starts the event queue consumption.  This is a blocking call.
	Run(ctx context.Context, consumers ...Consumer) error
}

Queue is an abstract message queue client, the exact implementation is defined by the implementation. A queue must always replay all active resources, so we can witness missed events on a restart. If an error is encontered when the consumer is invoked, then the event must be requeued to mitigate transient errors.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL