Class OutboxMetricsBinder

java.lang.Object
com.aim2be.platform.outbox.OutboxMetricsBinder

public class OutboxMetricsBinder extends Object
Micrometer binder for the outbox metrics enumerated in .planning/26-stage-b-outbox-parity.md §OQ-5:
  • im2be_outbox_pending_total — gauge of PENDING row count (polled from OutboxRecordRepository.countByStatus(com.aim2be.platform.outbox.OutboxRecord.Status)).
  • im2be_outbox_publish_latency_seconds — timer recorded by the publisher on each successful publish (hot or cold).
  • im2be_outbox_backlog_age_seconds — gauge of now() - oldest_pending.created_at; published when at least one PENDING row exists, else reports zero.
  • im2be_outbox_publish_failure_total — counter incremented on every failed hot or cold publish attempt.

Per-topic metrics are tagged (topic=<name>). Per-topic timers and counters are created lazily and memoised so they appear in /actuator/prometheus on demand.

No-op mode. When constructed with a null MeterRegistry (Spring Boot Actuator absent in the consumer service), all recording methods become no-ops and gauge registration is skipped. This keeps the auto-configuration usable in non-observed contexts (e.g. integration tests, minimal services) without forcing Micrometer as a hard dependency on consumers.

  • Constructor Details

    • OutboxMetricsBinder

      public OutboxMetricsBinder(io.micrometer.core.instrument.MeterRegistry registry, OutboxRecordRepository repository)
      Constructs the binder. When registry is non-null, immediately registers the two gauge metrics (pending_total + backlog_age_seconds); per-topic latency + failure metrics are lazy-registered on first use. When registry is null the binder operates in no-op mode (see class Javadoc).
      Parameters:
      registry - Micrometer registry, or null to disable metric recording entirely
      repository - JPA repository providing the gauge data sources; never null
  • Method Details

    • recordPublishLatency

      public void recordPublishLatency(String topic, Duration duration)
      Records one publish latency observation under the im2be_outbox_publish_latency_seconds{topic=...} timer. No-op when no MeterRegistry is wired (see class Javadoc).
      Parameters:
      topic - the topic the publish targeted
      duration - wall-clock duration of the publish
    • recordFailure

      public void recordFailure(String topic)
      Increments the im2be_outbox_publish_failure_total{topic=...} counter. No-op when no MeterRegistry is wired (see class Javadoc).
      Parameters:
      topic - the topic whose publish failed