Using offsets

Hi!

I want to be crash-safe so I save the last consumed offset processed in an event listener.
How do I calculate the next offset to start reading from, as I don’t want to reprocess the event already handled?

2 Likes

In general, you can’t:

The format of absolute offsets is opaque to the client: no client-side transformation of an offset is guaranteed to return a meaningful offset.

(source: https://docs.daml.com/1.7.0/app-dev/grpc/proto-docs.html#ledgeroffset)

But the good news is that the starting offset you pass in requests is exclusive, meaning that you can safely memorize the last offset you received and use it to ask for events following the one for which you saved a valid offset. Note that the ending offset (if provided) is inclusive instead.

I’ll have a better look at the documentation, but it appears that this is in fact poorly documented.

Thanks for the good question!

2 Likes

I created this PR to document it. If you believe there are other parts of the documentation that can be improved in this regard, please add your review. :bowing_man:

3 Likes

Thanks!

Works perfectly fine, as long as one understands the threading model in rxjava :slight_smile:

“If you have no problems, buy a goat.”

Per

3 Likes