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/
Click to show internal directories.
Click to hide internal directories.