inbox

command
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Example: inbox

A message broker delivers at least once. One message can therefore reach a handler more than one time, and a handler that is not idempotent then charges a card two times or sends two emails.

drel.Inbox suppresses the duplicate. Claim writes a dedupe row inside the caller's transaction, next to the application write, so the two commit together or neither commits.

Key concepts shown:

  • Claim: the first delivery proceeds, and the second returns ErrDuplicateMessage.
  • Atomicity: a handler that fails rolls the dedupe row back with its work, so the broker can deliver the message again.
  • Fail: records the failed attempt outside the rolled-back transaction.
  • Two handlers: the key is the pair of message and handler, so a second handler processes the same message one time of its own.
  • Purge: deletes the old rows.

Runs against in-memory SQLite. No external database is needed.

Usage:

go run ./examples/inbox/

Jump to

Keyboard shortcuts

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