Interface ConnectionSupplier
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
This exists because the outbox is worth nothing unless its insert commits with the business
write, and only the application knows where its transaction lives. Under Spring that is
DataSourceUtils.getConnection(dataSource), which returns the connection bound to the
current transaction; elsewhere it is usually a thread local the framework maintains.
What it must never be is dataSource::getConnection. A fresh connection with
auto-commit on will insert the outbox row immediately and independently, so a later rollback of
the business work leaves a message queued for something that never happened — the exact fault
the pattern was adopted to prevent, now harder to notice because the code looks right.
The connection returned here is borrowed, not owned: JdbcOutboxStore will not close
it, because the transaction that owns it is not finished.
-
Method Summary
-
Method Details
-
get
- Returns:
- the connection belonging to the caller's current transaction
- Throws:
SQLException- if no connection can be obtained
-