Class OrderedQueueBuilder<T>

java.lang.Object
org.acemq.amqp.core.OrderedQueueBuilder<T>
Type Parameters:
T - payload type

public final class OrderedQueueBuilder<T> extends Object
Says how a stream of messages is partitioned, and then declares it.

 OrderedQueue<Order> orders = mq.ordered("orders", Order.class)
         .partitions(8)
         .keyedBy(Order::customerId)
         .onFailure(OrderedQueue.OnFailure.RETRY_IN_PLACE, 3, Duration.ofSeconds(2))
         .declare();
 

The key is required and has no sensible default. A partitioned queue with no key is an ordinary queue with extra steps.

  • Method Details

    • partitions

      public OrderedQueueBuilder<T> partitions(int partitions)
      Parameters:
      partitions - how many queues to spread keys across. This is the ceiling on parallelism and cannot be changed later without draining first, because the partition a key belongs to is a function of the count
      Returns:
      a builder with that many partitions
    • keyedBy

      public OrderedQueueBuilder<T> keyedBy(Function<T,String> key)
      Parameters:
      key - what decides the sequence a message belongs to — a customer, an account, an aggregate identifier. Messages sharing one are handled in the order they were sent
      Returns:
      a builder using it
    • prefetch

      public OrderedQueueBuilder<T> prefetch(int prefetch)
      Parameters:
      prefetch - how many messages each partition's consumer may hold. Safe for ordering at any value, because one consumer dispatches serially
      Returns:
      a builder with that prefetch
    • onFailure

      public OrderedQueueBuilder<T> onFailure(OrderedQueue.OnFailure onFailure)
      Parameters:
      onFailure - what a failing handler does to the sequence
      Returns:
      a builder with that policy
    • onFailure

      public OrderedQueueBuilder<T> onFailure(OrderedQueue.OnFailure onFailure, int attempts, Duration delay)
      Parameters:
      onFailure - what a failing handler does to the sequence
      attempts - how many times to try, when the policy retries
      delay - how long to wait between attempts, during which the partition is stalled
      Returns:
      a builder with that policy
    • declare

      public OrderedQueue<T> declare()
      Creates the exchange, the partition queues and the bindings.
      Returns:
      the queue, ready to publish to and consume from
    • toString

      public String toString()
      Overrides:
      toString in class Object