Class InMemoryDeadLetterQueue

java.lang.Object
dev.agenor.runtime.deadletter.InMemoryDeadLetterQueue
All Implemented Interfaces:
DeadLetterQueue

public final class InMemoryDeadLetterQueue extends Object implements DeadLetterQueue
A DeadLetterQueue holding a bounded window of recent entries in memory.

The default for a runtime that has not been given a durable one. It is a window, not an archive: past capacity() entries the oldest are evicted, and nothing survives a restart. totalRecorded() is what tells you whether eviction has happened, so that a full window is distinguishable from a quiet one.

Those limits are the honest shape for this transport. The in-memory dispatcher does not redeliver, so a dead letter here is a message that is already lost; keeping it is what makes the loss visible, and keeping it forever would only trade one leak for another.

Since:
0.32.0
  • Field Details

    • DEFAULT_CAPACITY

      public static final int DEFAULT_CAPACITY
      Entries kept when no capacity is given.
      See Also:
  • Constructor Details

    • InMemoryDeadLetterQueue

      public InMemoryDeadLetterQueue()
      Creates a queue holding DEFAULT_CAPACITY entries.
    • InMemoryDeadLetterQueue

      public InMemoryDeadLetterQueue(int capacity)
      Creates a queue holding at most capacity entries.
      Parameters:
      capacity - the number of entries to keep; must be positive
      Throws:
      IllegalArgumentException - if capacity is not positive
  • Method Details

    • record

      public void record(DeadLetter deadLetter)
      Description copied from interface: DeadLetterQueue
      Records a message the framework has given up on.

      Called from a delivery path that has already failed, so it must not throw: an implementation that cannot store the entry logs and returns rather than turning a lost message into a second failure on top of it.

      Specified by:
      record in interface DeadLetterQueue
      Parameters:
      deadLetter - what was given up on and why; must not be null
    • recent

      public List<DeadLetter> recent(int limit)
      Description copied from interface: DeadLetterQueue
      Returns the most recently dead-lettered messages, newest first.

      What "recent" reaches depends on the implementation and is a property worth knowing before relying on it: an in-memory queue holds a bounded window and forgets on restart, while one backed by a durable stream reaches as far back as that stream is retained.

      Specified by:
      recent in interface DeadLetterQueue
      Parameters:
      limit - the maximum number of entries to return; must be positive
      Returns:
      the entries, newest first, at most limit of them; never null, possibly empty
    • capacity

      public int capacity()
      Returns how many entries this queue keeps before evicting the oldest.
      Returns:
      the capacity; always positive
    • totalRecorded

      public long totalRecorded()
      Returns how many entries have ever been recorded, including those since evicted.

      Compare it with the size of recent(int) to tell a window that has overflowed from one that has not.

      Returns:
      the total ever recorded; never negative