Documentation
¶
Overview ¶
Package inbox is a consumer's guard against handling a redelivered event twice, on any SQL engine that supplies its statement.
The package exports:
- Engine, the statement the inbox runs, compiled for one engine
- Inbox, the inbox on one engine's statement, with New, which checks the engine and returns one, and Inbox.Claim, which records a consumer's handling of an event and reports whether it is the first
Delivery is at least once, so a handler can see an event again. An Inbox is built with New over an Engine, the statement one engine's module compiles. One such module is go-messaging's postgres sub-module, which ships the inbox's table in the same migration set as the outbox's. Inbox.Claim records, in the handler's own transaction, that a consumer is handling an event, and reports whether it is the first time. The claim commits with the handler's work or rolls back with it, so when a handler fails, its redelivery can claim the event again. This package holds no SQL and imports no driver.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// Claim records a consumer's handling of an event, affecting one row on
// the first claim and none on a repeat. Parameters: consumer, source, and
// id. It runs on the handler's transaction, a sqlate *Tx, so it may
// declare a transaction required.
Claim query.Statement
}
Engine is the SQL a database engine's module supplies for the inbox. The inbox holds no SQL of its own, so an engine is required, and New checks that it defines its statement with exactly the parameters named here.
type Inbox ¶
type Inbox struct {
// contains filtered or unexported fields
}
Inbox claims events for their consumers on one engine's statement.
func New ¶
New returns an inbox over eng, once eng defines its statement with the parameters Engine names.
func (*Inbox) Claim ¶
func (in *Inbox) Claim(ctx context.Context, tx *sqlate.Tx, consumer string, e event.Event) (first bool, err error)
Claim records that consumer is handling e, in the handler's transaction tx, and reports whether this is the first time. A handler that gets false has already committed its handling of e, so it skips the event and acknowledges it. A handler that gets true does its work on the same tx; a rollback releases the claim, so a redelivery can claim e again.
consumer names the handler, typically its subscription's Name: consumers claim an event independently. The claim keys on e's source and id, the pair that identifies a CloudEvents event.