Class StreamOffset

java.lang.Object
org.acemq.amqp.api.StreamOffset

public final class StreamOffset extends Object
Where in a stream a consumer starts reading.

The idea a queue has no room for. A queue delivers what is there and forgets it; a stream keeps everything until retention removes it, and every consumer holds its own position. Saying where to start is therefore a normal thing to do rather than a recovery procedure, and it is what replay is.

next() is the default, and deliberately the timid one. A consumer deployed against a stream holding a year of history and starting at first() will read the year — which is sometimes exactly right and is never what somebody wanted by accident.

  • Method Details

    • first

      public static StreamOffset first()
      Returns:
      everything the stream still holds, oldest first
    • last

      public static StreamOffset last()
      Returns:
      the last chunk the stream holds, and everything after it. Not the same as next(): this replays a little, because a stream is written in chunks and the last one is where the broker can cheaply seek to
    • next

      public static StreamOffset next()
      Returns:
      only messages written after this consumer attached; the default
    • at

      public static StreamOffset at(long offset)
      Parameters:
      offset - the exact position to resume from, normally one past the last offset this consumer recorded as handled
      Returns:
      that position
    • from

      public static StreamOffset from(Instant timestamp)
      Parameters:
      timestamp - the point in time to start from
      Returns:
      the first message written at or after that moment
    • lastly

      public static StreamOffset lastly(Duration age)
      Parameters:
      age - how far back to start
      Returns:
      the first message written within that period, so ofHours(1) reads the last hour and then continues
    • toConsumerArgument

      public Object toConsumerArgument()
      The value the broker expects as the x-stream-offset consumer argument.

      Types matter here rather than only values: the broker reads a string as a keyword, a number as an absolute offset and a date as a timestamp, so a position sent as the wrong type is not rejected but silently means something else.

      Returns:
      the argument value
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object