Package com.gruelbox.transactionoutbox
Interface Submitter
- All Known Implementing Classes:
ExecutorSubmitter
public interface Submitter
Called by
TransactionOutbox
to submit work for background processing.-
Method Summary
Modifier and TypeMethodDescriptionvoid
submit
(TransactionOutboxEntry entry, Consumer<TransactionOutboxEntry> localExecutor) Submits a transaction outbox task for processing.static Submitter
Schedules background worh with aThreadPoolExecutor
, sized to matchForkJoinPool.commonPool()
(or one thread, whichever is the larger), with a maximum queue size of 16384 before work is discarded.static Submitter
withExecutor
(Executor executor) Schedules background work using a localExecutor
implementation.
-
Method Details
-
withExecutor
Schedules background work using a localExecutor
implementation.Shortcut for
ExecutorSubmitter.builder().executor(executor).build()
.- Parameters:
executor
- The executor.- Returns:
- The submitter.
-
withDefaultExecutor
Schedules background worh with aThreadPoolExecutor
, sized to matchForkJoinPool.commonPool()
(or one thread, whichever is the larger), with a maximum queue size of 16384 before work is discarded.- Returns:
- The submitter.
-
submit
Submits a transaction outbox task for processing. TheTransactionOutboxEntry
is provided, along with alocalExecutor
which can run the work immediately. An implementation may validly do any of the following:- Submit a call to
localExecutor
in a local thread, e.g. using anExecutor
. This is what implementations returned bywithExecutor(Executor)
orwithDefaultExecutor()
will do, and is recommended in almost all cases. - Serialize the
TransactionOutboxEntry
, send it to another instance (e.g. via a queue) and have the handler code callTransactionOutbox.processNow(TransactionOutboxEntry)
. Such an approach should not generally be necessary sinceTransactionOutbox.flush()
is designed to be called repeatedly on multiple instances. This means there is a degree of load balancing built into the system, but when dealing with very high load, very low run-time tasks, this can get overwhelmed and direct multi-instance queuing can help balance the load at source. Note: it is recommended that theinvocation
property of theTransactionOutboxEntry
be serialized usingInvocationSerializer.createDefaultJsonSerializer()
- Pass the
entry
directly to thelocalExecutor
. This will run the work immediately in the calling thread and is therefore generally not recommended; the calling thread will be either the thread callingTransactionOutbox.schedule(Class)
(effectively making the work synchronous) or the background poll thread (limiting work in progress to one). It can, however, be useful for test cases.
- Parameters:
entry
- The entry to process.localExecutor
- Provides a means of running the work directly locally (it is effectively just a call toTransactionOutbox.processNow(TransactionOutboxEntry)
).
- Submit a call to
-