Class TenantAwareOutboxPoller

java.lang.Object
org.chenile.orchestrator.process.outbox.TenantAwareOutboxPoller

public class TenantAwareOutboxPoller extends Object
Drains the outbox of every tenant named by the TenantSupplier.

For each tenant the poller clears the thread's ContextContainer and runs OutboxDispatcher.poll() inside TenantScope.run(String, Runnable), which sets the tenant and pins it on the thread. With a tenant-routing DataSource every connection opened while draining (the claim, the handler's transaction, a REQUIRES_NEW transaction deep inside a handler, the acknowledgement) therefore goes to that tenant's database, even if code the handler calls changes the ContextContainer.

A failure while draining one tenant (its database is down, say) is logged and does not stop the other tenants. The thread's original context is restored after each tenant. With no tenants (a single-tenant deployment, or no multi-datasource-utils) this is one dispatcher.poll() in the current context.

  • Field Details

    • logger

      private static final org.slf4j.Logger logger
    • dispatcher

      private final OutboxDispatcher dispatcher
    • tenants

      private final TenantSupplier tenants
    • tenantScope

      private final TenantScope tenantScope
  • Constructor Details

  • Method Details

    • poll

      public void poll()
      One background polling cycle across all tenants.
    • pollTenant

      public void pollTenant(String tenant)
      Drains one tenant's outbox; failures are logged, not thrown.
    • tenants

      public List<String> tenants()
      The supplier's tenants, without blanks or duplicates.