Documentation
¶
Overview ¶
Package txoutbox provides reusable transaction hook and outbox dispatch helpers.
Index ¶
Constants ¶
View Source
const ( OutboxStatusPending = "pending" OutboxStatusProcessing = "processing" OutboxStatusRetrying = "retrying" OutboxStatusSucceeded = "succeeded" OutboxStatusFailed = "failed" )
Variables ¶
View Source
var ( ErrStoreNotConfigured = errors.New("txoutbox: store not configured") ErrPublisherNotConfigured = errors.New("txoutbox: publisher not configured") )
Functions ¶
Types ¶
type ClaimInput ¶
type ClaimInput struct {
Consumer string
Now time.Time
Limit int
Topic string
LockUntil *time.Time
}
ClaimInput controls batched outbox claiming.
type DispatchInput ¶
type DispatchInput struct {
Consumer string
Topic string
Limit int
Now time.Time
RetryDelay time.Duration
ClaimLockTo *time.Time
}
DispatchInput controls outbox dispatch behavior.
type DispatchResult ¶
DispatchResult captures batch dispatch outcomes.
func DispatchBatch ¶
func DispatchBatch[Scope any](ctx context.Context, store Store[Scope], scope Scope, publisher Publisher, input DispatchInput) (DispatchResult, error)
DispatchBatch claims pending outbox messages and publishes them.
type Hooks ¶
type Hooks struct {
// contains filtered or unexported fields
}
Hooks tracks post-commit hooks collected during a transaction callback.
func (*Hooks) AfterCommit ¶
func (h *Hooks) AfterCommit(hook PostCommitHook)
AfterCommit registers a hook to run after transaction commit.
type Message ¶
type Message struct {
ID string
TenantID string
OrgID string
Topic string
MessageKey string
PayloadJSON string
HeadersJSON string
CorrelationID string
Status string
AttemptCount int
MaxAttempts int
LastError string
AvailableAt time.Time
LockedAt *time.Time
LockedBy string
PublishedAt *time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
Message stores durable side-effect events for post-commit dispatch.
type PostCommitHook ¶
type PostCommitHook func() error
PostCommitHook defines work executed only after a successful transaction commit.
type Store ¶
type Store[Scope any] interface { EnqueueOutboxMessage(ctx context.Context, scope Scope, record Message) (Message, error) ClaimOutboxMessages(ctx context.Context, scope Scope, input ClaimInput) ([]Message, error) MarkOutboxMessageSucceeded(ctx context.Context, scope Scope, id string, publishedAt time.Time) (Message, error) MarkOutboxMessageFailed(ctx context.Context, scope Scope, id, failureReason string, nextAttemptAt *time.Time, failedAt time.Time) (Message, error) ListOutboxMessages(ctx context.Context, scope Scope, query Query) ([]Message, error) }
Store defines durable post-commit side-effect message persistence.
Click to show internal directories.
Click to hide internal directories.