TransactionalOutbox

interface TransactionalOutbox

TransactionalOutbox is the main entry point for the library. It is responsible for:

  • adding outbox items (instant or not)

  • handling an instant outbox

  • monitoring the outbox items

To instantiate a TransactionalOutbox, use the TransactionalOutboxBuilder.

Monitor function is to be called periodically to process the outbox items, with a new transaction and a frequency of your choice. It represents a polling consumer of the outbox items.

Example:

val outbox = TransactionalOutboxBuilder()
.withStore(store)
.withProcessor(processor)
.build()

outbox.addOutboxItem(MyOutboxPayload("id", "name"))

@Scheduled(fixedRate = 1000)
fun processOutbox() {
outbox.monitor()
}

Functions

add
Link copied to clipboard
abstract fun add(type: OutboxType, payload: OutboxPayload, shouldPublishAfterInsertion: Boolean = false)

Adds an outbox with will be processed on scheduled manner.

cleanup
Link copied to clipboard
abstract fun cleanup()

Deletes all the outbox items that have been completed and have gone past their retention duration.

monitor
Link copied to clipboard
open fun monitor()
abstract fun monitor(id: Long? = null)

Monitors the outbox for new items and processes them

processInstantOutbox
Link copied to clipboard
abstract fun processInstantOutbox(outbox: OutboxItem)

Will process an instant outbox, should be called by the listener of the event emitted by add with the shouldPublishAfterInsertion as true and in a separate transaction.

shutdown
Link copied to clipboard
abstract fun shutdown()

Blocks new tasks and waits up to a specified period of time for all tasks to be completed. If that time expires, the execution is stopped immediately. Any tasks that did not start execution will have their corresponding item's status set to PENDING. Shutdown is idempotent, so multiple invocations will have no additional effect. Note that if the library is used in Spring, you may notice two invocations of shutdown, one from the @PreDestroy and one via the automatic inference as described here.