Package org.keycloak.events.outbox
Class OutboxDrainerTask
java.lang.Object
org.keycloak.events.outbox.OutboxDrainerTask
- All Implemented Interfaces:
KeycloakSessionTask,ScheduledTask
Drains the generic outbox for one registered
entryKind: locks
due PENDING rows, hands them off to the kind's
OutboxDeliveryHandler, and transitions each row based on the
returned OutboxDeliveryOutcome.
One drainer instance per registered kind. Each is wrapped in a
ClusterAwareScheduledTaskRunner at scheduling time so in an
HA deployment only one node drains a given kind per interval, even
though every node schedules the timer.
Concurrency within a single tick is cheap because rows are locked
PESSIMISTIC_WRITE via FOR UPDATE SKIP LOCKED by the
store, and each row is transitioned to a terminal state (DELIVERED /
back to PENDING with a future next_attempt_at / DEAD_LETTER)
before the transaction commits.
Per-tick housekeeping after the drain pass:
- Promote rows whose
createdAtis older thanOutboxConfig.pendingMaxAge()to DEAD_LETTER (backstop so stuck rows can't sit forever). - Purge DELIVERED rows past
OutboxConfig.deliveredRetention(). - Purge DEAD_LETTER rows past
OutboxConfig.deadLetterRetention().
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final OutboxConfigprotected final OutboxDeliveryHandlerprotected final Function<KeycloakSession,OutboxStore> -
Constructor Summary
ConstructorsConstructorDescriptionOutboxDrainerTask(OutboxConfig config, OutboxDeliveryHandler handler, Function<KeycloakSession, OutboxStore> storeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddrain(KeycloakSession session, OutboxStore store) protected voidhandleRetry(OutboxStore store, OutboxEntryEntity row, String errorMessage) protected voidprocessOne(KeycloakSession session, OutboxStore store, OutboxEntryEntity row) protected voidprotected voidprotected voidvoidrun(KeycloakSession session) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.keycloak.timer.ScheduledTask
getTaskName
-
Field Details
-
config
-
handler
-
storeFactory
-
-
Constructor Details
-
OutboxDrainerTask
public OutboxDrainerTask(OutboxConfig config, OutboxDeliveryHandler handler, Function<KeycloakSession, OutboxStore> storeFactory)
-
-
Method Details
-
run
- Specified by:
runin interfaceKeycloakSessionTask
-
drain
-
processOne
-
handleRetry
-
promoteStaleQueuedToDeadLetter
-
purgeDeliveredOlderThanRetention
-
purgeDeadLetterOlderThanRetention
-