Hi,
Using Kafka 0.6.
I'm trying to use get offsets but it doesn't seem to work as I expect. I
have a test topic that has some messages in it. Here's the output of a
test client that starts from offset 0 and prints all messages/offsets for
the topic:
Consumed message:foo offset: 12
Consumed message:bar offset: 24
Consumed message:foo offset: 36
Consumed message:bar offset: 48
Consumed message:hello offset: 62
Consumed message:world offset: 76
Here's a class to print the last n offsets:
public class SimpleConsumerDemo
{
public static void main(String[] args)
{
SimpleConsumer simpleConsumer = new SimpleConsumer("localhost", 9092,
1000, 1024);
long[] offsets = simpleConsumer.getOffsetsBefore("test", 0, -1L, 1);
for (long l : offsets) {
System.out.println("offset: " + l);
}
}
}
Running this as above, with 1 offset, yields expected results:
----output-----
offset: 76
However, asking for 3 offsets yields unexpected results:
change to: long[] offsets = simpleConsumer.getOffsetsBefore("test", 0, -1L,
3);
----output-----
offset: 76
offset: 0
I expected:
----output-----
offset: 76
offset: 62
offset: 48
Any idea why I did not get what I was looking for/what I am doing wrong?