Documentation
¶
Index ¶
Constants ¶
const ( DefaultPollingInterval = 100 * time.Millisecond DefaultDirectWorkers = 8 DefaultDirectQueueSize = 1024 DefaultOutboxDepthSampleEvery = 10 DefaultPollerBatchSize = 100 DefaultPollerBatchBudget = 5 * time.Second DefaultPollerGracePeriod = 10 * time.Second DefaultPollerMaxBackoff = time.Minute DefaultPublishTimeout = 2 * time.Second )
Variables ¶
var ( ErrDirectEmitRequiresDB = errors.New("direct emit requires a non-nil db") ErrDirectEmitRequiresBus = errors.New("direct emit requires a non-nil bus") )
var DefaultOptions = &Options{ PollingInterval: DefaultPollingInterval, Serializer: serialization.NewProtobufSerializer(), OutboxTableName: "event_outbox", DirectEmit: false, DirectWorkers: DefaultDirectWorkers, DirectQueueSize: DefaultDirectQueueSize, OutboxDepthSampleEvery: DefaultOutboxDepthSampleEvery, PollerBatchSize: DefaultPollerBatchSize, PollerBatchBudget: DefaultPollerBatchBudget, PollerGracePeriod: DefaultPollerGracePeriod, PollerMaxBackoff: DefaultPollerMaxBackoff, PublishTimeout: DefaultPublishTimeout, }
Functions ¶
This section is empty.
Types ¶
type DBForwarder ¶
type DBForwarder struct {
// contains filtered or unexported fields
}
func (*DBForwarder) NotifyCommitted ¶ added in v0.17.0
func (fw *DBForwarder) NotifyCommitted(ctx context.Context, evs []*events.SerializedEvent)
NotifyCommitted implements outbox.CommitNotifier. It enqueues events for the direct-emit worker pool. When the queue is full, events are dropped and the poller handles them on its next cycle.
func (*DBForwarder) Stop ¶
func (fw *DBForwarder) Stop() error
type DebeziumForwarder ¶ added in v0.16.0
type DebeziumForwarder struct {
// contains filtered or unexported fields
}
func NewDebeziumForwarder ¶ added in v0.16.0
func NewDebeziumForwarder(db db.DB, bus bus.Bus, options *DebeziumOptions) (*DebeziumForwarder, error)
func (*DebeziumForwarder) Start ¶ added in v0.16.0
func (fw *DebeziumForwarder) Start(ctx context.Context) error
func (*DebeziumForwarder) Stop ¶ added in v0.16.0
func (fw *DebeziumForwarder) Stop() error
type DebeziumMessage ¶ added in v0.16.0
type DebeziumMessage struct {
Payload struct {
Before interface{} `json:"before"`
After struct {
ID string `json:"id"`
Topic string `json:"topic"`
Payload []byte `json:"payload"`
CreatedAt int64 `json:"created_at"`
} `json:"after"`
Source struct {
Version string `json:"version"`
Connector string `json:"connector"`
Name string `json:"name"`
TsMs int64 `json:"ts_ms"`
Snapshot string `json:"snapshot"`
Db string `json:"db"`
Sequence interface{} `json:"sequence"`
TsUs int64 `json:"ts_us"`
TsNs int64 `json:"ts_ns"`
Table string `json:"table"`
ServerID int `json:"server_id"`
Gtid interface{} `json:"gtid"`
File string `json:"file"`
Pos int `json:"pos"`
Row int `json:"row"`
Thread int `json:"thread"`
Query interface{} `json:"query"`
} `json:"source"`
Transaction interface{} `json:"transaction"`
Op string `json:"op"`
TsMs int64 `json:"ts_ms"`
TsUs int64 `json:"ts_us"`
TsNs int64 `json:"ts_ns"`
} `json:"payload"`
}
type DebeziumOptions ¶ added in v0.16.0
type DebeziumOptions struct {
Serializer serialization.Serializer
DebeziumStream string
DebeziumSubject string
SubscriberName string
Logger *zap.Logger
}
type Metrics ¶ added in v0.17.0
type Metrics struct {
DirectEnqueued metric.Int64Counter
DirectPublished metric.Int64Counter
DirectFailed metric.Int64Counter
DirectDropped metric.Int64Counter
DirectDeleteFailed metric.Int64Counter
PollerPublished metric.Int64Counter
PollerFailed metric.Int64Counter
OutboxDepth metric.Int64Gauge
OutboxOldestAge metric.Float64Gauge
EmitLatencySeconds metric.Float64Histogram
}
Metrics holds the OpenTelemetry instruments used by the forwarder. It is safe to share a single *Metrics across forwarders — all operations on the underlying instruments are concurrency-safe.
Use NewMetrics to construct against a MeterProvider. Pass nil for the forwarder's Metrics option to disable metric recording entirely.
func NewMetrics ¶ added in v0.17.0
func NewMetrics(mp metric.MeterProvider) (*Metrics, error)
NewMetrics constructs the forwarder's OTel instruments against the provided MeterProvider. Pass otel.GetMeterProvider() to attach to the process-wide global provider, or a custom one for test/multi-tenant isolation.
Returns the first instrument-creation error so the caller can surface it during client setup.
type Options ¶
type Options struct {
PollingInterval time.Duration
Serializer serialization.Serializer
OutboxTableName string
Logger *zap.Logger
// DirectEmit enables the push-based happy path: after a successful
// EventTx/EventsTx commit, events are handed to the forwarder's worker
// pool for immediate publish + row deletion, bypassing the poller.
DirectEmit bool
// DirectWorkers bounds the concurrency of direct emits.
DirectWorkers int
// DirectQueueSize is the buffer depth of the direct-emit channel. When
// full, events are dropped and left for the poller.
DirectQueueSize int
// OutboxDepthSampleEvery controls how often (in poller cycles) the
// outbox table depth and oldest row age are sampled into Metrics. Zero
// disables.
OutboxDepthSampleEvery int
// PollerBatchSize bounds how many rows one poll locks and publishes. A
// full batch triggers the next poll right away.
PollerBatchSize int
// PollerBatchBudget bounds how long one poll keeps publishing, and so how
// long it holds its row locks. Rows left over are picked up by the next
// poll right away. Rows are published one at a time to keep their order.
PollerBatchBudget time.Duration
// PollerGracePeriod makes the poller skip rows younger than this, so it
// does not race the direct-emit workers on fresh events. It only applies
// with DirectEmit and relies on ULID event ids. Zero uses the default,
// negative disables it.
PollerGracePeriod time.Duration
// PollerMaxBackoff caps how far the polling interval grows while
// publishing keeps failing.
PollerMaxBackoff time.Duration
// PublishTimeout bounds every single publish, so an unreachable bus
// fails fast instead of holding the poller's row locks.
PublishTimeout time.Duration
// Metrics is optional. When nil the forwarder records nothing. Construct
// with NewMetrics(mp) to attach to an OpenTelemetry MeterProvider.
Metrics *Metrics
}