Class PushPullQueueCore

java.lang.Object
net.blakez.bppmq.core.queue.PushPullQueueCore

public class PushPullQueueCore extends Object
Core domain object for push-pull queue operations. Manages message persistence and retrieval through the MessageRecordRepository.
Author:
Peter Blakeley : @pblakez pb@blakez.org
  • Constructor Details

    • PushPullQueueCore

      public PushPullQueueCore(MessageRecordRepository repository)
      Constructor for PushPullQueueCore.
      Parameters:
      repository - The repository for message persistence.
  • Method Details

    • push

      public Result<MessageRecord> push(String topic, String message)
      Pushes a single message to the specified topic. Thread-safe: Operations on the same topic are serialized to prevent race conditions.
      Parameters:
      topic - The topic to push the message to.
      message - The message content to push.
      Returns:
      A Result containing the created MessageRecord or errors.
    • pull

      public Result<MessageRecord> pull(String topic, long index)
      Pulls a single message from the specified topic at the given index.
      Parameters:
      topic - The topic to pull from.
      index - The index of the message to pull.
      Returns:
      A Result containing the MessageRecord or errors.
    • pullBatch

      public Result<List<MessageRecord>> pullBatch(String topic, long index, long batchSize)
      Pulls a batch of messages from the specified topic starting at the given index.
      Parameters:
      topic - The topic to pull from.
      index - The starting index for the batch.
      batchSize - The number of messages to pull.
      Returns:
      A Result containing a list of MessageRecords or errors.
    • pullFrom

      public Result<List<MessageRecord>> pullFrom(String topic, long from, long batchSize)
      Pulls messages from the specified topic starting from the given index. This method retrieves available messages at or after the specified index, up to the batch size limit.
      Parameters:
      topic - The topic to pull from.
      from - The minimum index to start searching from.
      batchSize - The maximum number of messages to retrieve.
      Returns:
      A Result containing a list of MessageRecords found or errors.
    • pushBatch

      public Result<MetaRecord> pushBatch(String topic, List<String> messages)
      Pushes a batch of messages to the specified topic. Thread-safe: Operations on the same topic are serialized to prevent race conditions.
      Parameters:
      topic - The topic to push messages to.
      messages - The list of message contents to push.
      Returns:
      A Result containing the MetaRecord with updated topic information or errors.
    • meta

      public Result<MetaRecord> meta(String topic)
      Retrieves metadata information for the specified topic.
      Parameters:
      topic - The topic to get metadata for.
      Returns:
      A Result containing the MetaRecord or errors.
    • countFrom

      public Result<Long> countFrom(String topic, long from)
      Counts the number of messages available from a specific index onwards.
      Parameters:
      topic - The topic to count messages from.
      from - The starting index to count from (inclusive).
      Returns:
      A Result containing the count of messages from the specified index or errors.
    • clearBefore

      public Result<MetaRecord> clearBefore(String topic, long index)
      Clears messages in the specified topic before the given index.
      Parameters:
      topic - The topic to clear messages from.
      index - The index before which to clear messages (exclusive).
      Returns:
      A Result containing the updated MetaRecord or errors.