You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@kafka.apache.org by Nathan Marz <na...@gmail.com> on 2012/05/31 09:45:22 UTC

Getting the offset of a message in 0.7.0

Given a MessageAndOffset object, what's the best way to get that message's
offset (and not the offset of the next message)? Would it be this:

long actualOffset(MessageAndOffset msg) {
    return msg.offset() - msg.message().serializedSize();
}

Re: Getting the offset of a message in 0.7.0

Posted by Jun Rao <ju...@gmail.com>.
Nathan,

This can be tricky, especially with compressed messages (where offsets are
only moved cross compressed unit). The easiest way is probably to remember
the offset of the previous message yourself.

Thanks,

Jun

On Thu, May 31, 2012 at 12:45 AM, Nathan Marz <na...@gmail.com> wrote:

> Given a MessageAndOffset object, what's the best way to get that message's
> offset (and not the offset of the next message)? Would it be this:
>
> long actualOffset(MessageAndOffset msg) {
>    return msg.offset() - msg.message().serializedSize();
> }
>