Class EventPosition

java.lang.Object
com.azure.messaging.eventhubs.models.EventPosition

public final class EventPosition extends Object
Defines a position of an EventData in the Event Hub partition. The position can be an offset, sequence number, or enqueued time.
  • Method Details

    • earliest

      public static EventPosition earliest()
      Corresponds to the location of the first event present in the partition. Use this position to begin receiving from the first event that was enqueued in the partition which has not expired due to the retention policy.
      Returns:
      An EventPosition set to the start of an Event Hub stream.
    • latest

      public static EventPosition latest()
      Corresponds to the end of the partition, where no more events are currently enqueued. Use this position to begin receiving from the next event to be enqueued in the partition when receiveFromPartition() invoked.
      Returns:
      An EventPosition set to the end of an Event Hubs stream and listens for new events.
    • fromEnqueuedTime

      public static EventPosition fromEnqueuedTime(Instant enqueuedDateTime)
      Creates a position at the given Instant. Corresponds to a specific instance within a partition to begin looking for an event. The event enqueued after the requested enqueuedDateTime becomes the current position.
      Parameters:
      enqueuedDateTime - The instant, in UTC, from which the next available event should be chosen.
      Returns:
      An EventPosition object.
    • fromOffset

      public static EventPosition fromOffset(long offset)
      Creates a position to an event in the partition at the provided offset. The event at that offset will not be included. Instead, the next event is returned.

      The offset is the relative position for event in the context of the stream. The offset should not be considered a stable value, as the same offset may refer to a different event as events reach the age limit for retention and are no longer visible within the stream.

      Parameters:
      offset - The offset of the event within that partition.
      Returns:
      An EventPosition object.
    • fromSequenceNumber

      public static EventPosition fromSequenceNumber(long sequenceNumber)
      Creates a position to an event in the partition at the provided sequence number. The event with the sequence number will not be included. Instead, the next event is returned.
      Parameters:
      sequenceNumber - is the sequence number of the event.
      Returns:
      An EventPosition object.
    • fromSequenceNumber

      public static EventPosition fromSequenceNumber(long sequenceNumber, boolean isInclusive)
      Creates a position at the given sequence number. If isInclusive is true, the event with the same sequence number is returned. Otherwise, the next event in the sequence is received.
      Parameters:
      sequenceNumber - is the sequence number of the event.
      isInclusive - If true, the event with the sequenceNumber is included; otherwise, the next event will be received.
      Returns:
      An EventPosition object.
    • isInclusive

      public boolean isInclusive()
      Gets the boolean value of if the event is included. If true, the event with the sequenceNumber is included; otherwise, the next event will be received.
      Returns:
      The boolean if the event will be received.
    • getOffset

      public String getOffset()
      Gets the relative position for event in the context of the stream. The offset should not be considered a stable value, as the same offset may refer to a different event as events reach the age limit for retention and are no longer visible within the stream.
      Returns:
      The offset of the event within that partition.
    • getSequenceNumber

      public Long getSequenceNumber()
      Gets the sequence number of the event.
      Returns:
      The sequence number of the event.
    • getEnqueuedDateTime

      public Instant getEnqueuedDateTime()
      Gets the instant, in UTC, from which the next available event should be chosen.
      Returns:
      The instant, in UTC, from which the next available event should be chosen.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object