Class FilesystemClaimCheckStore

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

public final class FilesystemClaimCheckStore extends Object implements ClaimCheckStore
A claim-check store on a filesystem.

Useful where the filesystem is shared and durable — an NFS mount, a persistent volume — and the honest middle ground between a map and object storage. On a container's local disk it is the in-memory store with extra steps: the consumer is on another host and finds nothing.

Object storage is the usual right answer, and a store in front of S3 or Azure Blob Storage is three short methods. This one exists because "write it to the mount everything already has" is a real deployment and not a bad one.

Writes are atomic

The payload is written to a temporary file and moved into place. Without that, a consumer fast enough to read the key before the writer finished gets a truncated payload and a parse error somewhere unhelpful — and messaging is exactly the arrangement that makes a consumer that fast normal rather than unlikely.

  • Constructor Details

    • FilesystemClaimCheckStore

      public FilesystemClaimCheckStore(Path directory)
      Parameters:
      directory - where payloads are written; created if it is not there
  • 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
    • toString

      public String toString()
      Overrides:
      toString in class Object