Documentation
¶
Overview ¶
Package providers defines the Provider interface and DeployTarget compatibility matrix for workflow-plugin-eventbus. Each provider (nats, kafka, kinesis) implements Provider and emits typed IaC resource declarations for its supported deploy targets.
Package providers — RuntimeBroker abstraction.
RuntimeBroker decouples publish/subscribe + stream/consumer management from the specific broker backend. Provider implementations live in sub-packages (providers/nats, providers/pgchannel, future kafka/kinesis) and are selected at module Start time from ClusterConfig.Provider.
This interface is consumed by:
- module.clusterModule (Connect + lifecycle)
- module.streamModule (EnsureStream)
- module.consumerModule (EnsureConsumer)
- steps/publish.go (Publish)
- steps/consume.go (Consume — bounded-batch pull semantics)
- steps/ack.go (Ack)
- trigger.go (Subscribe — long-lived push handler)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateProviderTarget ¶
func ValidateProviderTarget(provider string, target DeployTarget) error
ValidateProviderTarget returns an error if the provider × target combination is unsupported. It is called at config-load time so misconfigured deployments are rejected before any IaC resources are emitted.
Types ¶
type Connection ¶
type Connection interface {
// Close releases the underlying broker connection / pool. Idempotent.
Close() error
// Provider returns the provider identifier this connection belongs to
// (e.g. "nats", "pgchannel"). Used for diagnostics + telemetry.
Provider() string
}
Connection is a provider-specific connection handle. Concrete types live in each provider sub-package and embed whatever broker client they need (*nats.Conn, *pgxpool.Pool, etc.).
Callers MUST treat Connection as opaque and only pass it back into RuntimeBroker methods. Close releases all underlying resources.
type DeployTarget ¶
type DeployTarget string
DeployTarget identifies the deployment platform for an event-bus cluster.
const ( // TargetDigitalOceanApp deploys to DigitalOcean App Platform. TargetDigitalOceanApp DeployTarget = "digitalocean.app_platform" // TargetDigitalOceanManagedKafka deploys to DigitalOcean Managed Kafka. TargetDigitalOceanManagedKafka DeployTarget = "digitalocean.managed_kafka" // TargetAWSECS deploys to AWS ECS (Elastic Container Service). TargetAWSECS DeployTarget = "aws.ecs" // TargetAWSEKS deploys to AWS EKS (Elastic Kubernetes Service). TargetAWSEKS DeployTarget = "aws.eks" // TargetAWSManagedKafka deploys to AWS MSK (Managed Streaming for Apache Kafka). TargetAWSManagedKafka DeployTarget = "aws.msk" // TargetAWSKinesis deploys to AWS Kinesis Data Streams. TargetAWSKinesis DeployTarget = "aws.kinesis" // TargetKubernetes deploys to a generic Kubernetes cluster. TargetKubernetes DeployTarget = "kubernetes" // TargetSelfHosted deploys to a self-managed host (Docker, bare metal). TargetSelfHosted DeployTarget = "self_hosted" )
type HealthCheck ¶
type HealthCheck struct {
// URI is the address that was probed.
URI string
// Status is the typed health state.
Status HealthStatus
// Err is non-nil when Status is HealthStatusDegraded or HealthStatusUnreachable.
Err error
}
HealthCheck is the result of a liveness probe against an event-bus URI.
type HealthStatus ¶
type HealthStatus string
HealthStatus is the typed health state returned by Provider.Probe.
const ( // HealthStatusHealthy indicates the broker is reachable and fully operational. HealthStatusHealthy HealthStatus = "healthy" // HealthStatusDegraded indicates the broker is reachable but impaired // (e.g. a replica is down, JetStream is slow). HealthStatusDegraded HealthStatus = "degraded" // HealthStatusUnreachable indicates the broker did not respond within the probe timeout. HealthStatusUnreachable HealthStatus = "unreachable" )
type MessageHandler ¶
type MessageHandler func(ctx context.Context, msg *eventbusv1.Message) error
MessageHandler is invoked by RuntimeBroker.Subscribe for each delivered message. Returning nil acknowledges the message; returning a non-nil error naks it, counting toward ConsumerConfig.max_deliver.
type Provider ¶
type Provider interface {
// Name returns the provider identifier: "nats", "kafka", or "kinesis".
Name() string
// Resources returns the IaC resource declarations required to provision
// the event-bus cluster described by cfg on the given deploy target.
// cfg is passed as a pointer because proto messages embed sync.Mutex via
// protoimpl.MessageState and must not be copied by value.
// Returns an error if the provider × target combination is unsupported
// or if cfg is invalid for this provider.
Resources(cfg *eventbusv1.ClusterConfig, target DeployTarget) ([]iac.Resource, error)
// ConnectionString derives the broker connection string from provisioned state.
// env selects environment-specific outputs (e.g. "prod", "staging").
ConnectionString(state iac.State, env string) (string, error)
// StreamResources returns the IaC resource declarations required to
// declare the given streams against an already-provisioned cluster
// (represented by state). Streams are pointers for the same reason as cfg.
StreamResources(streams []*eventbusv1.StreamConfig, state iac.State) ([]iac.Resource, error)
// Probe probes the event-bus cluster at uri and returns its health state.
Probe(uri string) HealthCheck
}
Provider is the interface all event-bus provider adapters must implement. Each provider translates a ClusterConfig + DeployTarget into a set of typed IaC resource declarations without directly calling cloud APIs.
Implementations live at providers/{nats,kafka,kinesis}/.
type RuntimeBroker ¶
type RuntimeBroker interface {
// Connect opens a connection to the broker described by cfg. The returned
// Connection is opaque to callers and is passed back into subsequent
// EnsureStream / EnsureConsumer / Publish / Subscribe / Ack calls.
Connect(ctx context.Context, cfg *eventbusv1.ClusterConfig) (Connection, error)
// EnsureStream creates or updates the stream described by cfg. Implementations
// MUST be idempotent: calling EnsureStream twice with the same cfg is a no-op.
EnsureStream(ctx context.Context, conn Connection, cfg *eventbusv1.StreamConfig) error
// EnsureConsumer creates or updates the consumer described by cfg on the named
// stream. Implementations MUST be idempotent.
EnsureConsumer(ctx context.Context, conn Connection, streamName string, cfg *eventbusv1.ConsumerConfig) error
// Publish publishes a single message via the broker. The returned
// PublishResponse carries provider-assigned sequence / timestamp metadata.
Publish(ctx context.Context, conn Connection, req *eventbusv1.PublishRequest) (*eventbusv1.PublishResponse, error)
// Subscribe attaches handler to streamName / consumerName and blocks until
// ctx is cancelled or an unrecoverable error occurs. Returning nil from
// handler acks the message; returning an error naks it (delivery counted
// against max_deliver per ConsumerConfig).
//
// Subscribe is the long-lived "push" path used by trigger.eventbus.subscribe.
// For bounded-batch pull semantics (step.eventbus.consume — return up to
// batch_size messages bounded by max_wait, then return) use Consume instead.
Subscribe(ctx context.Context, conn Connection, streamName, consumerName string, handler MessageHandler) error
// Consume returns up to req.batch_size already-delivered messages from the
// durable consumer named req.consumer on the named stream, blocking at
// most req.max_wait for the batch to fill. Returns an empty
// ConsumeResponse when no messages are available within max_wait (NOT an
// error).
//
// Each returned Message.ack_token is opaque to callers and must be passed
// back through Ack (typically via step.eventbus.ack) to acknowledge the
// message. Implementations choose the token format (NATS reply subject,
// "<stream>:<consumer>:<id>" for pgchannel, etc.).
//
// streamName is passed positionally (rather than embedded in req) because
// the proto ConsumeRequest does not carry stream identity; callers
// (typically step.eventbus.consume) resolve it from the registered
// ConsumerConfig before dispatching here, mirroring the EnsureConsumer
// shape.
//
// Consume is the bounded-pull counterpart to Subscribe: it does not
// register a long-lived handler — each call sets up + tears down whatever
// fetch infrastructure the provider needs, returns a single batch, and
// exits. This separation per Group A's TODO cleanly splits pull
// (step.eventbus.consume) from push (trigger.eventbus.subscribe).
Consume(ctx context.Context, conn Connection, streamName string, req *eventbusv1.ConsumeRequest) (*eventbusv1.ConsumeResponse, error)
// Ack acknowledges a previously delivered message identified by ackToken
// (Message.ack_token). Used by step.eventbus.ack for explicit-ack flows.
Ack(ctx context.Context, conn Connection, ackToken string) error
}
RuntimeBroker abstracts publish/subscribe + stream/consumer operations across providers (nats, pgchannel, future kafka/kinesis).
Implementations MUST be safe for concurrent use across goroutines once Connect has returned a Connection. All methods take a context; cancellation MUST propagate to in-flight broker operations.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package kafka provides a stub implementation of the kafka event-bus Provider.
|
Package kafka provides a stub implementation of the kafka event-bus Provider. |
|
Package kinesis provides a stub implementation of the kinesis event-bus Provider.
|
Package kinesis provides a stub implementation of the kinesis event-bus Provider. |
|
Package nats provides the NATS event-bus Provider implementation.
|
Package nats provides the NATS event-bus Provider implementation. |
|
Package pgchannel — see subject_match.go for the package doc.
|
Package pgchannel — see subject_match.go for the package doc. |
|
internal/testutil
Package testutil — testcontainers helpers for the pgchannel provider tests.
|
Package testutil — testcontainers helpers for the pgchannel provider tests. |