SimpleOutboxHandler

abstract class SimpleOutboxHandler<T : OutboxPayload>(supportedType: OutboxType, objectMapper: ObjectMapper, clock: Clock, maxRetries: Int, payloadType: Class<T>) : OutboxHandler

This class purpose is to create an easy way to create an outbox handler.

In order to achieve this, the following assumptions are made:

  1. Object mapper is used for serializing and deserializing outbox (Before invoking handleWithParsedPayload the object mapper deserializer is invoked)

  2. Linear retries are applied 1 minute from now (clock is used)

Note: This is a quick solution to avoid duplicate code. It should be extracted to support multiple retries policies and support configurable serialize.

Constructors

SimpleOutboxHandler
Link copied to clipboard
fun <T : OutboxPayload> SimpleOutboxHandler(supportedType: OutboxType, objectMapper: ObjectMapper, clock: Clock, maxRetries: Int, payloadType: Class<T>)

Types

Companion
Link copied to clipboard
object Companion

Functions

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

Returns the next execution time for the outbox item.

getRetentionDuration
Link copied to clipboard
open override 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
open override fun getSupportedType(): OutboxType

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

handle
Link copied to clipboard
open override 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.

handleWithParsedPayload
Link copied to clipboard
abstract fun handleWithParsedPayload(payload: T)

This method is invoked after the payload is deserialized. The payload is already of type T and can be cast to it. This method should be implemented by the user.

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

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

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

Serializes the payload into a string.