Class InMemoryClaimCheckStore

java.lang.Object
org.acemq.amqp.patterns.InMemoryClaimCheckStore
All Implemented Interfaces:
ClaimCheckStore

public final class InMemoryClaimCheckStore extends Object implements ClaimCheckStore
A claim-check store in a map, for tests.

Not for production, and the reason is the point of the pattern. The payloads are held in the publisher's heap — which is where they were going to be anyway, so this removes them from the broker and nothing else. A claim check that does not outlive the process that wrote it is a message nobody else can read, and every consumer in another process gets "the claim check is not in the store".

It is genuinely useful for a test, where the publisher and consumer are the same JVM and the point being proved is the framing rather than the storage.

  • Constructor Details

    • InMemoryClaimCheckStore

      public InMemoryClaimCheckStore()
  • Method Details

    • put

      public String put(byte[] content)
      Description copied from interface: ClaimCheckStore
      Stores a payload.
      Specified by:
      put in interface ClaimCheckStore
      Parameters:
      content - the bytes
      Returns:
      the key the message will carry, which must be unique for the life of the store
    • get

      public Optional<byte[]> get(String key)
      Description copied from interface: ClaimCheckStore
      Redeems a claim check.
      Specified by:
      get in interface ClaimCheckStore
      Parameters:
      key - what the message carried
      Returns:
      the payload, or empty when the store no longer holds it — which is retention having expired underneath a message that outlived it
    • delete

      public void delete(String key)
      Description copied from interface: ClaimCheckStore
      Removes a payload.

      Not called by the codec. Deleting on read would break the second consumer of the same message, and deleting on acknowledgement would break a replay — so when a payload may be removed is a retention decision, and retention decisions belong to whoever owns the data.

      Specified by:
      delete in interface ClaimCheckStore
      Parameters:
      key - what to remove
    • size

      public int size()
      Returns:
      how many payloads are held
    • clear

      public void clear()
      Empties the store, which is what a test between cases wants.
    • toString

      public String toString()
      Overrides:
      toString in class Object