minghuaw / azeventhubs

Unofficial Azure Event Hubs SDK over AMQP 1.0 for rust
5 stars 2 forks source link

`EventPosition::SequenceNumber` seems to still start from the beginning #11

Closed jackgerrits closed 1 year ago

jackgerrits commented 1 year ago

Sorry I don't have a self contained repro on this one but I call read_events_from_partition and pass EventPosition::earliest() and read a few events. I then save the sequence number to start from and start a new reading stream but this time using EventPosition::from_sequence_number(pos, false).

async fn get_start_position(partition_id: &str) -> EventPosition {
    // Some logic to determine the start pos
    let starting_pos: i64 = get_sequence_number_to_start_from(&partition_id);
    match starting_pos {
        -1 => EventPosition::earliest(),
        pos => EventPosition::from_sequence_number(pos, false),
    }
}

// ...

let starting_pos = get_start_position(&checkpoint, &partition_id).await;
// ...
let stream = client
                .read_events_from_partition(
                    &partition_id,
                    starting_pos,
                    ReadEventOptions::default()
                )
                .await;

The behavior I am seeing is that even though I am passing an EventPosition that is later than the oldest event I am still reading from the oldest event. (The same event as I first received when I starting reading from `EventPosition::earliest()``

Am I misconfiguring something perhaps?

minghuaw commented 1 year ago

Hi @jackgerrits

I am not able to reproduce this behaviour. I have added a simple example consumer_read_from_position.rs which basically let the consumer read 30 events from the beginning, records the last known sequence number (ie. the sequence number of the 30th event), closes the stream, then call read_events_from_partition() again but with the recorded last known sequence number, and it seems to work just as expected. The partition was first populated with 300 events with the event_hub_producer_example.rs which contains a monotonically increasing number.

I have also tried closing the consumer client entirely and create a new one, which also works as expected. Could you let me know more about your configuration?

jackgerrits commented 1 year ago

Apologies, my repro is really vague. I'll spend some more time seeing if the issue is in my code. I'll close this and reopen if I have a clearer description.