OutboxHandler

interface OutboxHandler

OutboxHandler is responsible for:

  • handling the outbox item

  • serializing the payload

  • calculating the next execution time

  • checking if the max retries has been reached

  • handling the payload and

  • handling the failure.

Example:

class MyOutboxHandler : OutboxHandler {
override fun getSupportedType(): OutboxType {
return MyOutboxType
}
override fun serialize(payload: OutboxPayload): String {
return payload.toString()
}
override fun getNextExecutionTime(currentRetries: Long): Instant {
return Instant.now()
}
override fun hasReachedMaxRetries(retries: Long): Boolean {
return retries >= 3
}
override fun handle(payload: String) {
// handle the payload
}
override fun handleFailure(payload: String) {
// handle the failure
// e.g. send an email to the admin
}
}

Functions

getNextExecutionTime
Link copied to clipboard
abstract fun getNextExecutionTime(currentRetries: Long): Instant

Returns the next execution time for the outbox item.

getRetentionDuration
Link copied to clipboard
abstract fun getRetentionDuration(): Duration

Returns the amount of time that the outbox items of this handler's type should be retained. The outbox items will be deleted after this amount of time has passed after their completion.

getSupportedType
Link copied to clipboard
abstract fun getSupportedType(): OutboxType

Returns the type of the outbox item that this handler can handle.

handle
Link copied to clipboard
abstract fun handle(payload: String)

Handles the outbox item.

handleFailure
Link copied to clipboard
abstract fun handleFailure(payload: String)

Handles the outbox item when it has reached the maximum number of retries.

hasReachedMaxRetries
Link copied to clipboard
abstract fun hasReachedMaxRetries(retries: Long): Boolean

Returns true if the outbox item has reached the maximum number of retries.

serialize
Link copied to clipboard
abstract fun serialize(payload: OutboxPayload): String

Serializes the payload into a string.

Inheritors

SimpleOutboxHandler
Link copied to clipboard